Skip to content

知らない分野を、原文にたどりつくまで芋づる式に掘る Claude Code のスキル

Python

fetch: 双方向制御文字をエスケープし、APM でインストールが止まらないようにする

fuj1g0n70c7161a1e91
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f7e91e..88b5459 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,10 @@ imozuruのバージョンごとの変更を記録します。
## [未公開]
+### 修正
+
+- AIエージェント向けのスキルなどを管理する [APM(Agent Package Manager)](https://github.com/microsoft/apm) で、不可視文字の検出によりインストールが止まる問題を直しました。原文のファイル名を検査する正規表現の双方向制御文字を Unicode エスケープで表記し、危険な名前を拒否する動作を変えずに、`--force` なしでインストールできるようにしました。
+
## [2.1.0] - 2026-10-26
### 追加
diff --git a/skills/imozuru/scripts/fetch.py b/skills/imozuru/scripts/fetch.py
index 0d0a7f9..40e3e27 100755
--- a/skills/imozuru/scripts/fetch.py
+++ b/skills/imozuru/scripts/fetch.py
@@ -1054,7 +1054,7 @@ def valid_source_name(name: str) -> bool:
return (bool(name.strip(" .")) and name == name.rstrip(" .")
and not any(c in name for c in "/\\:<>\"|?*")
and not any(ord(c) < 32 or 127 <= ord(c) <= 159 for c in name)
- and not re.search(r"[‎‏‪-‮⁦-⁩]", name)
+ and not re.search(r"[\u200e\u200f\u202a-\u202e\u2066-\u2069]", name)
and device not in {"CON", "PRN", "AUX", "NUL", "CONIN$", "CONOUT$"}
and not re.fullmatch(r"(?:COM|LPT)[1-9¹²³]", device))
diff --git a/tests/test_fetch.py b/tests/test_fetch.py
index d10bc55..c7a722a 100644
--- a/tests/test_fetch.py
+++ b/tests/test_fetch.py
@@ -21,6 +21,26 @@ PUBLIC_IP = "93.184.215.14"
fetch.resolve = lambda host: {PUBLIC_IP}
+class SourceNameTests(unittest.TestCase):
+ def test_rejects_all_bidi_controls_in_filename_pattern(self):
+ controls = [0x200E, 0x200F, *range(0x202A, 0x202F), *range(0x2066, 0x206A)]
+ for codepoint in controls:
+ with self.subTest(codepoint=f"U+{codepoint:04X}"):
+ self.assertFalse(fetch.valid_source_name(f"paper{chr(codepoint)}.md"))
+
+ def test_accepts_characters_adjacent_to_bidi_ranges(self):
+ for codepoint in (0x200D, 0x2010, 0x2029, 0x202F, 0x2065, 0x206A):
+ with self.subTest(codepoint=f"U+{codepoint:04X}"):
+ self.assertTrue(fetch.valid_source_name(f"paper{chr(codepoint)}.md"))
+
+ def test_fetch_source_contains_no_literal_bidi_controls(self):
+ source = SCRIPT.read_text(encoding="utf-8")
+ controls = [0x200E, 0x200F, *range(0x202A, 0x202F), *range(0x2066, 0x206A)]
+ for codepoint in controls:
+ with self.subTest(codepoint=f"U+{codepoint:04X}"):
+ self.assertNotIn(chr(codepoint), source)
+
+
class FetchPreservationTests(unittest.TestCase):
def setUp(self):
tmp = tempfile.TemporaryDirectory()