知らない分野を、原文にたどりつくまで芋づる式に掘る Claude Code のスキル
Python
fetch: http(s) 以外の URL を取りに行かない (#10)
sousuke0422d73448d7f4a6
diff --git a/skills/imozuru/scripts/fetch.py b/skills/imozuru/scripts/fetch.pyindex 5327f54..6af1051 100755--- a/skills/imozuru/scripts/fetch.py+++ b/skills/imozuru/scripts/fetch.py@@ -369,6 +369,10 @@ def fetch_source(sources: Path, name: str, url: str, destination: Path) -> int:if not valid_source_name(name):print(f"FAIL\t{name!r}\t原文の名前は単一のファイル名にする")return 1+ # file:// や ftp:// を渡すと urllib が手元のファイルまで読み、sources/ に写してしまう+ if urllib.parse.urlsplit(url).scheme.lower() not in {"http", "https"}:+ print(f"FAIL\t{name}\thttp(s) の URL だけを取りに行く")+ return 1if X_POST.match(url):print(f"FAIL\t{name}\tX はログインの壁で本文が取れない(URL を map.md に残す)")diff --git a/tests/test_fetch.py b/tests/test_fetch.pyindex 8530099..82aad26 100644--- a/tests/test_fetch.py+++ b/tests/test_fetch.py@@ -187,6 +187,18 @@ class FetchPreservationTests(unittest.TestCase):self.assertEqual(self.run_fetch(), 1)self.assertEqual(list(self.sources.iterdir()), [])+ def test_non_http_url_is_rejected_without_reading(self):+ secret = Path(self.sources.parent) / "secret.txt"+ secret.write_text("local secret\n" * 200, encoding="utf-8")+ for url in (secret.as_uri(), "FILE://" + secret.as_posix(),+ "ftp://example.test/paper.txt", "-o/tmp/x"):+ with self.subTest(url=url):+ with patch.object(fetch, "download") as download:+ self.assertEqual(self.run_fetch(url), 1)+ download.assert_not_called()+ self.assertEqual(list(self.sources.iterdir()), [])+ self.assertIn("http(s) の URL だけを取りに行く", self.stdout.getvalue())+if __name__ == "__main__":unittest.main()