Skip to content
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

Merged
merged 1 commit into from
Feb 16, 2024
Merged

Conversation

takecchi
Copy link
Member

@takecchi takecchi commented Feb 16, 2024

Issue

変更内容

  • /test@example.comのようなパスパラメータを受け取り可能に

確認方法

@を含むユーザーIDのユーザーページを開けること

Summary by CodeRabbit

- バグ修正: `@`を含むユーザー名やパスパラメータが正しく処理されない問題を修正しました。これにより、`@`を含む任意のユーザー名でユーザー情報を正確に取得したり、パスパラメータを適切に受け取ったりすることが可能になります。

@takecchi takecchi merged commit 2bdc3a3 into main Feb 16, 2024
4 checks passed
@takecchi takecchi deleted the feature/issues-299 branch February 16, 2024 00:32
Copy link

github-actions bot commented Feb 16, 2024

Image description CodeRabbit

ウォークスルー

この変更では、@を含むユーザーネームやパスパラメータが正しく処理されるように、そのデコード方法を修正しました。これにより、アプリケーションは特殊文字を含むユーザーネームでも正確に動作します。

変更点

ファイル 概要
src/app/(menu)/(public)/[username]/page.tsx, src/app/(menu)/(public)/[username]/posts/[postId]/page.tsx params.usernameに含まれる@をデコードしてから使用または比較するように修正されています。これにより、usernameやパスパラメータに@が含まれている場合でも正しくユーザー情報を取得したり、パスパラメータを受け取ったりすることができます。

🐇

修正の祝福を込めて、小さな詩を一つ。

"特殊な名前も、今は問題なし、

'@'の謎、解けた喜び。

コードの海を、うさぎが跳ね回り、

新たな道、開かれた瞬間。" 🎉


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between dd8f474 and 9f4dbe9 commits.
Files selected (2)
  • src/app/(menu)/(public)/[username]/page.tsx (2)
  • src/app/(menu)/(public)/[username]/posts/[postId]/page.tsx (1)
Review comments generated (3)
  • Review: 3
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +73 to +74
const username = decodeURIComponent(params.username);
if (post.author.username !== username) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

この変更は、ユーザー名に@が含まれている場合でも正しく動作するようになりました。ただし、decodeURIComponent関数はエラーをスローする可能性があります。URLが不適切にエンコードされている場合や、無効なパーセントエンコーディングが含まれている場合などです。これらのエラーを適切に処理するために、try...catchブロックを使用してください。

-  const username = decodeURIComponent(params.username);
+  let username;
+  try {
+    username = decodeURIComponent(params.username);
+  } catch (e) {
+    // 適切なエラーハンドリングを行います。
+    console.error(e);
+    return;
+  }

Comment on lines +25 to +26
const username = decodeURIComponent(params.username);
const user = await getUser(username);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

decodeURIComponent関数は、不正なURIコンポーネントを渡された場合にエラーをスローします。そのため、この関数の呼び出しはtry-catchブロックで囲むべきです。これにより、ユーザーが不正なパラメータを送信した場合でもアプリケーションがクラッシュすることを防げます。

-  const username = decodeURIComponent(params.username);
+  let username;
+  try {
+    username = decodeURIComponent(params.username);
+  } catch (e) {
+    // 不正なパラメータを処理するための適切なエラーハンドリングを追加します。
+    return {};
+  }
   const user = await getUser(username);

Comment on lines +55 to +56
const username = decodeURIComponent(params.username);
const user = await getUser(username);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

同様に、decodeURIComponent関数の呼び出しはtry-catchブロックで囲むべきです。これにより、ユーザーが不正なパラメータを送信した場合でもアプリケーションがクラッシュすることを防げます。

-  const username = decodeURIComponent(params.username);
+  let username;
+  try {
+    username = decodeURIComponent(params.username);
+  } catch (e) {
+    // 不正なパラメータを処理するための適切なエラーハンドリングを追加します。
+    notFound();
+    return;
+  }
   const user = await getUser(username);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant