Skip to content

ディープリンクのレガシー経路で sgid/lid/lgid を厳密な正整数バリデーションで検証する#6007

Merged
TinyKitten merged 1 commit into
devfrom
fix/deep-link-legacy-validation
May 16, 2026
Merged

ディープリンクのレガシー経路で sgid/lid/lgid を厳密な正整数バリデーションで検証する#6007
TinyKitten merged 1 commit into
devfrom
fix/deep-link-legacy-validation

Conversation

@TinyKitten
Copy link
Copy Markdown
Member

@TinyKitten TinyKitten commented May 16, 2026

概要

useDeepLink のレガシー経路(sgid / lid / lgid 形式)で Number() + truthy 判定のみだったため、1.5Infinity のような値がそのまま GraphQL の Int 変数に渡り、下流でエラーになる可能性がありました。先行 PR #6003sids 側に導入済みの /^[1-9]\d*$/ バリデーションに揃え、不正値の場合はリンク全体を no-op にします。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • src/hooks/useDeepLink.ts: handleUrl のレガシー分岐で sgid / lid/^[1-9]\d*$/ の厳密な正整数として検証。lgid は省略可だが、指定された場合は同じ正規表現で検証し、不正なら lineId パスへフォールスルーせずリンク全体を no-op にする。
  • src/hooks/useDeepLink.test.tsx: it.each で 8 ケース(sgid の小数 / Infinity / 0 / 余分文字、lid の小数 / 指数表記、lgid の小数 / 任意文字列)を追加し、いずれもクエリ非発火・state 不変であることを担保。

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

Closes #6004

スクリーンショット(任意)

Summary by CodeRabbit

  • Bug Fixes

    • URL深リンク機能のパラメータ検証を強化しました。小数や不正な値などの無効なパラメータをより確実に検出・拒否するようになります。
  • Tests

    • パラメータ検証の妥当性を確認するテストケースを追加しました。

Review Change Stack

@TinyKitten TinyKitten self-assigned this May 16, 2026
@github-actions github-actions Bot added the react label May 16, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc34a220-8f76-485c-a132-beda3a4575e1

📥 Commits

Reviewing files that changed from the base of the PR and between c334ccb and f739af9.

📒 Files selected for processing (2)
  • src/hooks/useDeepLink.test.tsx
  • src/hooks/useDeepLink.ts

📝 Walkthrough

Walkthrough

useDeepLink フックのレガシーディープリンク経路(sgid/lid/lgid 形式)において、URL パラメータの入力検証をより厳密に強化しました。従来の Number() 変換と truthy 判定から、正の整数に対する正規表現ベースの厳密バリデーションに置き換え、不正な値が下流の GraphQL 呼び出しに渡るのを防ぎます。

Changes

レガシーディープリンクパラメータの厳密バリデーション

Layer / File(s) Summary
正の整数バリデーションの実装とテスト
src/hooks/useDeepLink.ts, src/hooks/useDeepLink.test.tsx
sgid/lid/lgid パラメータの入力値をトリムして /^[1-9]\d*$/ 正規表現で厳密に検証し、不正なら処理を中断。従来の Number() 変換と truthy チェックを廃止。包括的なパラメータ化テストで、小数・Infinity・0・不正文字・指数表記など各種不正ケースおよび組み合わせについて、fetch 呼び出しとステート更新が発生しないことを検証。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6003: 同じ useDeepLinksgid/lid/lgid 周りの URL 解析ロジックに対して、別の分岐(sids 形式)で既に厳密な正の整数バリデーションを導入していたため、本 PR はその検証パターンをレガシー経路に統一する直接的な関連変更です。

Suggested labels

react, validation

Poem

🐰 深いリンク、パラメータ検証よ
Number() から regex へと
小数や無限も今は拒む
正の整数のみを許しし
テストで守られし堅牢さ!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、レガシー経路での sgid/lid/lgid に対する厳密な正整数バリデーション導入という変更内容を明確かつ簡潔に表しており、メインの変更を適切に要約しています。
Description check ✅ Passed プルリクエストの説明は、テンプレートの主要セクション(概要、変更の種類、変更内容、テスト、関連Issue)をすべて適切に埋めており、変更内容・実装方法・テスト確認が明確に記載されています。
Linked Issues check ✅ Passed プルリクエストは linked issue #6004 で要求された「useDeepLink のレガシー経路で /^[1-9]\d*$/ による厳密な正整数バリデーションを導入する」という要件を完全に満たしており、sgid/lid/lgid に対する検証実装およびテストが追加されています。
Out of Scope Changes check ✅ Passed 変更は linked issue #6004 の要件である useDeepLink のレガシー経路の入力検証に完全に限定されており、範囲外の機能追加や不関連な修正は含まれていません。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/deep-link-legacy-validation

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

@TinyKitten TinyKitten merged commit 487c57f into dev May 16, 2026
7 checks passed
@TinyKitten TinyKitten deleted the fix/deep-link-legacy-validation branch May 16, 2026 15:14
@TinyKitten TinyKitten mentioned this pull request May 16, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useDeepLink: sgid / lid を厳密な正整数バリデーションで検証する

1 participant