-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
usernameに@を含められるように修正 #300
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ const getUser = cache(async (username: string) => { | |
}); | ||
|
||
export async function generateMetadata({ params }: Params): Promise<Metadata> { | ||
const user = await getUser(params.username); | ||
const username = decodeURIComponent(params.username); | ||
const user = await getUser(username); | ||
if (!user) { | ||
return {}; | ||
} | ||
|
@@ -51,7 +52,8 @@ export async function generateMetadata({ params }: Params): Promise<Metadata> { | |
} | ||
|
||
export default async function page({ params }: Params) { | ||
const user = await getUser(params.username); | ||
const username = decodeURIComponent(params.username); | ||
const user = await getUser(username); | ||
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同様に、 - const username = decodeURIComponent(params.username);
+ let username;
+ try {
+ username = decodeURIComponent(params.username);
+ } catch (e) {
+ // 不正なパラメータを処理するための適切なエラーハンドリングを追加します。
+ notFound();
+ return;
+ }
const user = await getUser(username); |
||
if (!user) { | ||
notFound(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,8 @@ export default async function page({ params }: Params) { | |
notFound(); | ||
} | ||
|
||
if (post.author.username !== params.username) { | ||
const username = decodeURIComponent(params.username); | ||
if (post.author.username !== username) { | ||
Comment on lines
+73
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この変更は、ユーザー名に - const username = decodeURIComponent(params.username);
+ let username;
+ try {
+ username = decodeURIComponent(params.username);
+ } catch (e) {
+ // 適切なエラーハンドリングを行います。
+ console.error(e);
+ return;
+ } |
||
redirect(`/${post.author.username}/posts/${post.id}`); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeRabbit
decodeURIComponent
関数は、不正なURIコンポーネントを渡された場合にエラーをスローします。そのため、この関数の呼び出しはtry-catchブロックで囲むべきです。これにより、ユーザーが不正なパラメータを送信した場合でもアプリケーションがクラッシュすることを防げます。