Skip to content

Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.

fix(validate_skill): parse a SKILL.md saved with a UTF-8 BOM (#181)

Shubham Srivastavae1184b49da08
diff --git a/tests/test_validate_skill.py b/tests/test_validate_skill.py
new file mode 100644
index 0000000..1bc8b33
--- /dev/null
+++ b/tests/test_validate_skill.py
@@ -0,0 +1,28 @@
+"""tools/validate_skill.py — frontmatter parsing is BOM-tolerant."""
+
+import importlib.util
+from pathlib import Path
+
+_SPEC = importlib.util.spec_from_file_location(
+ "validate_skill", Path(__file__).resolve().parent.parent / "tools" / "validate_skill.py"
+)
+validate_skill = importlib.util.module_from_spec(_SPEC)
+_SPEC.loader.exec_module(validate_skill)
+
+_SKILL = "---\nname: my-skill\ndescription: A test skill.\n---\n\n# Body\n"
+
+
+def test_audit_accepts_skill_without_bom(tmp_path):
+ p = tmp_path / "SKILL.md"
+ p.write_bytes(_SKILL.encode("utf-8"))
+ errors, _ = validate_skill.audit(str(p))
+ assert errors == []
+
+
+def test_audit_accepts_skill_with_utf8_bom(tmp_path):
+ # A SKILL.md saved with a UTF-8 BOM used to fail with "no valid YAML
+ # frontmatter" because the BOM broke text.startswith("---").
+ p = tmp_path / "SKILL.md"
+ p.write_bytes(b"\xef\xbb\xbf" + _SKILL.encode("utf-8"))
+ errors, _ = validate_skill.audit(str(p))
+ assert errors == []
diff --git a/tools/validate_skill.py b/tools/validate_skill.py
index 59daa67..86b4b21 100644
--- a/tools/validate_skill.py
+++ b/tools/validate_skill.py
@@ -127,7 +127,9 @@ def tool_base(entry):
def audit(path, lens="claude"):
rules = LENSES[lens]
label = rules["label"]
- text = Path(path).read_text(encoding="utf-8")
+ # utf-8-sig so a SKILL.md saved with a UTF-8 BOM still parses — otherwise the
+ # leading  makes text.startswith("---") false and frontmatter is missed.
+ text = Path(path).read_text(encoding="utf-8-sig")
fm, body = parse_frontmatter(text)
errors, warns = [], []
if fm is None: