Skip to content

Update snail traversal implementation and add SRI verification utility#254

Merged
myoshi2891 merged 2 commits into
mainfrom
dev-from-macmini
Feb 7, 2026
Merged

Update snail traversal implementation and add SRI verification utility#254
myoshi2891 merged 2 commits into
mainfrom
dev-from-macmini

Conversation

@myoshi2891

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

ウォークスルー

複数のドキュメントおよびユーティリティスクリプトを更新しました。Snailトラバーサル実装の TypeScript グローバル宣言を変更し、エッジケースの例を修正し、複数の HTML ファイルで Tailwind CDN と Prism リソースの参照を更新し、SRI ハッシュ値を検証するための新しい Python スクリプトを追加しました。

変更点

コホート / ファイル 概要
Snail トラバーサルドキュメント
JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README.md, README_react.html, Snail_Traversal_TS.ipynb
TypeScript グローバル宣言を declare interface Array<T> から declare global { interface Array<T> } に変更し、this パラメータを追加。エッジケース例を [].snail(1, 0) から [].snail(0, 0) に更新。ベンチマークテーブルの行を削除。実装を簡潔にした Jupyter ノートブックに置き換え。
Primitive Root ドキュメント
Mathematics/Number Theory/HackerRank/Easy/Primitive_Problem.html, Primitive_Problem.ipynb
Tailwind CDN を Play CDN に置き換え。Prism CSS および JavaScript リソースに integrity および crossorigin 属性を追加。Primitive Root の概念説明と LaTeX フォーマットを含むマークダウンコンテンツを追加。文字列内の空行表現を正規化。
ユーティリティスクリプト
verify_sri.py
外部リソースを取得して SHA-384 ハッシュを計算し、SRI 文字列を生成する新しい Python スクリプトを追加。エラーハンドリング付きの手続き型コード。

推定コードレビュー工数

🎯 3 (Moderate) | ⏱️ ~20 分

関連する可能性のある PR

  • PR #252: Snail トラバーサル実装および TypeScript グローバル/インターフェース拡張で Array.prototype.snail メソッドシグネチャを変更している点で関連。
  • PR #253: Array.prototype.snail のグローバル拡張と README のエッジケース例の両方を修正している点で関連。

ウサギの詩

🐰✨ snail() は今や世界をグローバルに呼び出し、
TypeScript の宣言もしっかり整備し、
Tailwind と Prism を新しい CDN に乗り替え、
SRI ハッシュで安全を検証する、
ウサギの足並みで着実に進む! 🐇🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, making it impossible to assess relevance to the changeset. Add a meaningful pull request description that explains the purpose and scope of the changes made in this PR.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main changes: updating the snail traversal implementation and adding a new SRI verification utility script.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev-from-macmini

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
Mathematics/Number Theory/HackerRank/Easy/Primitive_Problem.ipynb (1)

108-133: 🧹 Nitpick | 🔵 Trivial

euler_phi の実装がノートブック版とHTML版で異なる

ノートブック版(ここ)は 2 を特別扱いして奇数のみループしますが、HTML版(Line 358-376)は p=2 から p+=1 で統一ループしています。どちらも正しいですが、ノートブック版のほうが約2倍高速です。一貫性の観点から、どちらかに統一することを推奨します。

Mathematics/Number Theory/HackerRank/Easy/Primitive_Problem.html (2)

1362-1366: ⚠️ Potential issue | 🟠 Major

Prism.js スクリプトが二重にロードされている

Prism.js とそのプラグインが2箇所でロードされています:

  • Lines 1362-1366: SRI なし(React コンポーネントの前)
  • Lines 2329-2354: SRI あり(ファイル末尾)

二重ロードは予期しない動作(シンタックスハイライトの二重適用、グローバル状態の上書きなど)を引き起こす可能性があり、帯域幅も無駄になります。SRI 付きの方(Lines 2329-2354)のみを残し、Lines 1362-1366 を削除してください。

🐛 修正案: SRIなし版を削除
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.js"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.js"></script>
-        <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>

Also applies to: 2329-2354


41-52: ⚠️ Potential issue | 🟡 Minor

React/ReactDOM の script タグに crossorigin 属性が重複

Lines 42 と 45、Lines 48 と 51 でそれぞれ crossorigin が2回指定されています。HTML仕様上、同一属性の重複は無効です。1つに統一してください。

🔧 修正案
         <script
-            crossorigin
             src="https://unpkg.com/react@18/umd/react.production.min.js"
             integrity="sha384-nVQePqH/QE94Buf4g/4MI5NrqDYjdqT76Db87Fa6eINIs+Uk31kgOEWzrnD1NTqU"
             crossorigin="anonymous"
         ></script>
         <script
-            crossorigin
             src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
             integrity="sha384-MUPX27At97Bs+bFaX2430abc2842R4tKjE2Frtj/z5r8v8lT1oI5ls55Dk7c21DD"
             crossorigin="anonymous"
         ></script>
🤖 Fix all issues with AI agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README_react.html:
- Around line 251-254: Update the notebook's TypeScript declaration for
Array<T>. Locate the interface Array<T> declaration that defines
snail(rowsCount: number, colsCount: number): T[][] and change the method
signature to include the explicit this parameter so it reads snail(this: T[],
rowsCount: number, colsCount: number): T[][]; ensure the change targets the
snail method in the Array<T> interface so the notebook's type definition matches
the HTML version.

In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README.md:
- Line 340: The comment for the example invoking the snail method is incorrect:
update the comment on the line with [].snail(0, 0); to state that validation
passes because 0 * 0 = 0 equals this.length and that an empty array is returned
because the requested matrix has zero rows (not because validation failed or
because "1×1=1 ≠ 0"); look for the snail function/example entry (the [].snail(0,
0) example) and replace the misleading Japanese comment with one that accurately
describes that an empty result is returned due to zero dimensions.

In `@Mathematics/Number` Theory/HackerRank/Easy/Primitive_Problem.html:
- Around line 8-9: The page currently includes Tailwind via the Play CDN script
tag referencing "https://cdn.tailwindcss.com", which is intended for prototyping
and lacks SRI/version stability; replace this with a production-ready approach
by either (a) building and including a local precompiled Tailwind CSS file and
linking it with a <link rel="stylesheet">, or (b) using a versioned, CDN-hosted
prebuilt Tailwind CSS file (not the Play CDN) and include integrity (SRI) and
crossorigin attributes; update the existing script tag reference to the chosen
<link> and ensure the CSS is version-locked and served with integrity for
production use.

In `@Mathematics/Number` Theory/HackerRank/Easy/Primitive_Problem.ipynb:
- Around line 229-248: The LaTeX aligned lines (e.g. the strings starting with
"2^1 &\\equiv 2 \\pmod{7} \\\n" and the block for 3 ending with "3^6 &\\equiv 1
\\pmod{7}\n") are escaping line breaks incorrectly in the JSON: each LaTeX row
needs a double backslash in the rendered output, so update each trailing "\\\n"
in the aligned environment strings to "\\\\\n" (i.e. escape the backslash in the
JSON so the final string contains "\\" for LaTeX line breaks) for both the 2^..
block and the 3^.. block.

In `@verify_sri.py`:
- Around line 5-10: The urls list in verify_sri.py only includes CSS and
Tailwind and misses other external resources used in the HTML (e.g., Prism JS
plugins, React/ReactDOM); update verify_sri.py to either expand the urls
variable to include all known external resources (add Prism JS plugin URLs,
React/ReactDOM, etc.) or implement automatic extraction from the HTML by parsing
script and link tags and collecting href/src values into urls before SRI
verification (look for the variable urls in verify_sri.py and the code paths
that iterate it to verify SRI).
- Around line 12-22: requests.get is called without a timeout and without
checking the HTTP response, so the script can hang or hash error pages; update
the loop to call requests.get(url, timeout=...) and immediately verify the
response (e.g., call response.raise_for_status() or check response.ok) before
computing the hash with hashlib.sha384 and base64.b64encode, and handle
requests.exceptions.Timeout and requests.exceptions.HTTPError (or general
requests.RequestException) in the except block to print a clear error for that
URL.
- Around line 1-3: The script verify_sri.py directly imports and uses the
requests module (see the "import requests" line), but requests is missing from
requirements.txt; add an explicit requests entry to requirements.txt (matching
or compatible with the version in requirements.lock.txt), then regenerate or
sync your lock file (or run your dependency tooling) so the declared dependency
and lockfile remain consistent.

Comment on lines +251 to +254
<pre class="line-numbers"><code class="language-typescript">declare global {
interface Array&lt;T&gt; {
snail(this: T[], rowsCount: number, colsCount: number): T[][];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the files mentioned in the review comment
echo "=== Looking for the files ==="
find . -name "*README_react.html" -o -name "*Snail_Traversal_TS.ipynb" -o -name "README.md" | head -20

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 1378


🏁 Script executed:

#!/bin/bash
# Search for Snail Traversal directory
echo "=== Searching for Snail Traversal files ==="
find . -type d -name "*Snail*" 2>/dev/null
find . -name "*README_react.html" 2>/dev/null
find . -name "*Snail_Traversal_TS*" 2>/dev/null
</script>

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 2038


🏁 Script executed:

#!/bin/bash
# Read the HTML file around lines 251-254
echo "=== Checking README_react.html lines 240-265 ==="
sed -n '240,265p' "./JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/README_react.html"

echo ""
echo "=== Checking Snail_Traversal_TS.ipynb structure ==="
# Get the line count of the notebook
wc -l "./JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/Snail_Traversal_TS.ipynb"

echo ""
echo "=== Checking notebook for snail method declaration around line 29 ==="
sed -n '1,100p' "./JavaScript/2624. Snail Traversal/Claude Code Sonnet 4.5/Snail_Traversal_TS.ipynb" | grep -i "snail\|declare\|interface" -A 2 -B 2

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 2782


ノートブック版の型定義を HTML 版と同期する必要がある

HTML ファイル(行 251-254)では snail(this: T[], rowsCount: number, colsCount: number): T[][] として this パラメータが含まれていますが、ノートブック版(Snail_Traversal_TS.ipynb)では snail(rowsCount: number, colsCount: number): T[][] として this パラメータがありません。ノートブック版も this: T[] パラメータを追加し、両ファイル間の型定義を一致させてください。

🤖 Prompt for AI Agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README_react.html
around lines 251 - 254, Update the notebook's TypeScript declaration for
Array<T>. Locate the interface Array<T> declaration that defines
snail(rowsCount: number, colsCount: number): T[][] and change the method
signature to include the explicit this parameter so it reads snail(this: T[],
rowsCount: number, colsCount: number): T[][]; ensure the change targets the
snail method in the Array<T> interface so the notebook's type definition matches
the HTML version.


```typescript
[].snail(1, 0); // → [] (入力サイズ 0)
[].snail(0, 0); // → [] (1×1=1 ≠ 0のため空配列を返す)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

エッジケースのコメントが不正確

[].snail(0, 0) の場合、0 * 0 = 0this.length = 0 と一致するため、バリデーションは通過します。結果として空配列 [] が返りますが、それはバリデーション失敗ではなく、行数が0のため空の結果が返るという理由です。

コメントの「1×1=1 ≠ 0のため空配列を返す」は誤りです。

🐛 修正案
-    [].snail(0, 0); // → [] (1×1=1 ≠ 0のため空配列を返す)
+    [].snail(0, 0); // → [] (0×0=0 = length なのでバリデーション通過、行数0のため空配列)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[].snail(0, 0); // → [] (1×1=1 ≠ 0のため空配列を返す)
[].snail(0, 0); // → [] (0×0=0 = length なのでバリデーション通過、行数0のため空配列)
🤖 Prompt for AI Agents
In `@JavaScript/2624`. Snail Traversal/Claude Code Sonnet 4.5/README.md at line
340, The comment for the example invoking the snail method is incorrect: update
the comment on the line with [].snail(0, 0); to state that validation passes
because 0 * 0 = 0 equals this.length and that an empty array is returned because
the requested matrix has zero rows (not because validation failed or because
"1×1=1 ≠ 0"); look for the snail function/example entry (the [].snail(0, 0)
example) and replace the misleading Japanese comment with one that accurately
describes that an empty result is returned due to zero dimensions.

Comment on lines +8 to +9
<!-- Tailwind CSS (Play CDN - SRI非対応) -->
<script src="https://cdn.tailwindcss.com"></script>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Tailwind CSS Play CDN はプロダクション環境に不適切

cdn.tailwindcss.com の Play CDN はプロトタイピング用であり、SRI をサポートしておらず、ビルドごとに内容が変わる可能性があります。学習用コンテンツであれば許容範囲ですが、公開するページであれば、ビルド済み CSS やバージョン固定の CDN の使用を検討してください。

🤖 Prompt for AI Agents
In `@Mathematics/Number` Theory/HackerRank/Easy/Primitive_Problem.html around
lines 8 - 9, The page currently includes Tailwind via the Play CDN script tag
referencing "https://cdn.tailwindcss.com", which is intended for prototyping and
lacks SRI/version stability; replace this with a production-ready approach by
either (a) building and including a local precompiled Tailwind CSS file and
linking it with a <link rel="stylesheet">, or (b) using a versioned, CDN-hosted
prebuilt Tailwind CSS file (not the Play CDN) and include integrity (SRI) and
crossorigin attributes; update the existing script tag reference to the chosen
<link> and ensure the CSS is version-locked and served with integrity for
production use.

Comment on lines +229 to +248
"\\begin{aligned}\n",
"2^1 &\\equiv 2 \\pmod{7} \\\n",
"2^2 &\\equiv 4 \\pmod{7} \\\n",
"2^3 &\\equiv 1 \\pmod{7}\n",
"\\end{aligned}\n",
"$$\n",
"\n",
"ここで $1$ に戻ってしまい、${1,2,4}$ しか生成できません。\n",
"\n",
"### 3 を使った場合\n",
"\n",
"$$\n",
"\\begin{aligned}\n",
"3^1 &\\equiv 3 \\pmod{7} \\\n",
"3^2 &\\equiv 2 \\pmod{7} \\\n",
"3^3 &\\equiv 6 \\pmod{7} \\\n",
"3^4 &\\equiv 4 \\pmod{7} \\\n",
"3^5 &\\equiv 5 \\pmod{7} \\\n",
"3^6 &\\equiv 1 \\pmod{7}\n",
"\\end{aligned}\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

LaTeX aligned 環境の改行が壊れている可能性

JSON文字列内で \\\n\ + 改行になりますが、LaTeX の aligned 環境では行の区切りに \\ (バックスラッシュ2つ)が必要です。現在の記述では各行末が \ 1つ + 改行のみのため、Jupyter上でレンダリングすると改行が正しく表示されない可能性があります。

JSON内で \\\\ と記述すれば、出力文字列で \\ となり、正しいLaTeX改行になります。

🐛 修正例(1箇所目)
-                "2^1 &\\equiv 2 \\pmod{7} \\\n",
-                "2^2 &\\equiv 4 \\pmod{7} \\\n",
+                "2^1 &\\equiv 2 \\pmod{7} \\\\\\\\\n",
+                "2^2 &\\equiv 4 \\pmod{7} \\\\\\\\\n",

同様の問題が Lines 242-247 の 3 を使った場合のブロックにも存在します。

🤖 Prompt for AI Agents
In `@Mathematics/Number` Theory/HackerRank/Easy/Primitive_Problem.ipynb around
lines 229 - 248, The LaTeX aligned lines (e.g. the strings starting with "2^1
&\\equiv 2 \\pmod{7} \\\n" and the block for 3 ending with "3^6 &\\equiv 1
\\pmod{7}\n") are escaping line breaks incorrectly in the JSON: each LaTeX row
needs a double backslash in the rendered output, so update each trailing "\\\n"
in the aligned environment strings to "\\\\\n" (i.e. escape the backslash in the
JSON so the final string contains "\\" for LaTeX line breaks) for both the 2^..
block and the 3^.. block.

Comment thread verify_sri.py
Comment on lines +1 to +3
import hashlib
import requests
import base64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for dependency-related files
find . -type f \( -name "requirements*.txt" -o -name "setup.py" -o -name "setup.cfg" -o -name "pyproject.toml" -o -name "Pipfile" -o -name "poetry.lock" \) 2>/dev/null | head -20

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 130


🏁 Script executed:

#!/bin/bash
# Check if requests is listed in dependency files
find . -type f \( -name "requirements*.txt" -o -name "setup.py" -o -name "setup.cfg" -o -name "pyproject.toml" -o -name "Pipfile" \) 2>/dev/null -exec grep -l "requests" {} \;

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 111


🏁 Script executed:

#!/bin/bash
# List the directory structure to understand the project layout
ls -la

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 1763


🏁 Script executed:

#!/bin/bash
# Find the verify_sri.py file and check its context
find . -name "verify_sri.py" -type f

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 103


🏁 Script executed:

cat ./requirements.txt

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 143


🏁 Script executed:

cat ./requirements.lock.txt

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 2071


🏁 Script executed:

cat -n ./verify_sri.py | head -50

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 1015


requirements.txtrequests を明示的に追加する必要がある

requestsrequirements.lock.txt では管理されていますが、requirements.txt に明示的に記載されていません。このスクリプトが直接 requests をインポート・使用しているため、requirements.txtrequests を直接追加することを推奨します。

🤖 Prompt for AI Agents
In `@verify_sri.py` around lines 1 - 3, The script verify_sri.py directly imports
and uses the requests module (see the "import requests" line), but requests is
missing from requirements.txt; add an explicit requests entry to
requirements.txt (matching or compatible with the version in
requirements.lock.txt), then regenerate or sync your lock file (or run your
dependency tooling) so the declared dependency and lockfile remain consistent.

Comment thread verify_sri.py
Comment on lines +5 to +10
urls = [
"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/line-numbers/prism-line-numbers.min.css",
"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/toolbar/prism-toolbar.min.css",
"https://cdn.tailwindcss.com/3.4.1"
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

URL リストが HTML ファイルで使用されている全リソースをカバーしていない

このスクリプトは CSS リソースと Tailwind のみを対象としていますが、HTML ファイルでは Prism.js の JS プラグインや React/ReactDOM 等にも SRI が適用されています。スクリプトの有用性を高めるために、全対象リソースを含めるか、HTML ファイルから URL を自動抽出する仕組みを検討してください。

🤖 Prompt for AI Agents
In `@verify_sri.py` around lines 5 - 10, The urls list in verify_sri.py only
includes CSS and Tailwind and misses other external resources used in the HTML
(e.g., Prism JS plugins, React/ReactDOM); update verify_sri.py to either expand
the urls variable to include all known external resources (add Prism JS plugin
URLs, React/ReactDOM, etc.) or implement automatic extraction from the HTML by
parsing script and link tags and collecting href/src values into urls before SRI
verification (look for the variable urls in verify_sri.py and the code paths
that iterate it to verify SRI).

Comment thread verify_sri.py
Comment on lines +12 to +22
for url in urls:
try:
response = requests.get(url)
content = response.content
hash_obj = hashlib.sha384(content)
base64_hash = base64.b64encode(hash_obj.digest()).decode('utf-8')
print(f"URL: {url}")
print(f"SRI: sha384-{base64_hash}")
print("-" * 20)
except Exception as e:
print(f"Error fetching {url}: {e}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

requests.get にタイムアウトと応答ステータスチェックが欠落

  1. requests.get(url) にタイムアウトが指定されていないため、サーバーが応答しない場合に無限にブロックします。
  2. レスポンスのステータスコードを確認していないため、404 や 500 エラー時にも無効なコンテンツのハッシュを計算してしまいます。
🔧 修正案
 for url in urls:
     try:
-        response = requests.get(url)
+        response = requests.get(url, timeout=30)
+        response.raise_for_status()
         content = response.content
         hash_obj = hashlib.sha384(content)
         base64_hash = base64.b64encode(hash_obj.digest()).decode('utf-8')
         print(f"URL: {url}")
         print(f"SRI: sha384-{base64_hash}")
         print("-" * 20)
-    except Exception as e:
+    except requests.RequestException as e:
         print(f"Error fetching {url}: {e}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for url in urls:
try:
response = requests.get(url)
content = response.content
hash_obj = hashlib.sha384(content)
base64_hash = base64.b64encode(hash_obj.digest()).decode('utf-8')
print(f"URL: {url}")
print(f"SRI: sha384-{base64_hash}")
print("-" * 20)
except Exception as e:
print(f"Error fetching {url}: {e}")
for url in urls:
try:
response = requests.get(url, timeout=30)
response.raise_for_status()
content = response.content
hash_obj = hashlib.sha384(content)
base64_hash = base64.b64encode(hash_obj.digest()).decode('utf-8')
print(f"URL: {url}")
print(f"SRI: sha384-{base64_hash}")
print("-" * 20)
except requests.RequestException as e:
print(f"Error fetching {url}: {e}")
🧰 Tools
🪛 Ruff (0.14.14)

[error] 14-14: Probable use of requests call without timeout

(S113)


[warning] 21-21: Do not catch blind exception: Exception

(BLE001)

🤖 Prompt for AI Agents
In `@verify_sri.py` around lines 12 - 22, requests.get is called without a timeout
and without checking the HTTP response, so the script can hang or hash error
pages; update the loop to call requests.get(url, timeout=...) and immediately
verify the response (e.g., call response.raise_for_status() or check
response.ok) before computing the hash with hashlib.sha384 and base64.b64encode,
and handle requests.exceptions.Timeout and requests.exceptions.HTTPError (or
general requests.RequestException) in the except block to print a clear error
for that URL.

@myoshi2891 myoshi2891 changed the title Dev from macmini Update snail traversal implementation and add SRI verification utility Feb 7, 2026
@myoshi2891 myoshi2891 merged commit 16ca72b into main Feb 7, 2026
1 check passed
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