Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

fix(hooks): tokenize script attributes so a quoted ">" cannot truncate the tag

Agrici Danielbc2bf3a1664e
diff --git a/hooks/validate-schema.py b/hooks/validate-schema.py
index 70de4a1..b26d1da 100755
--- a/hooks/validate-schema.py
+++ b/hooks/validate-schema.py
@@ -53,8 +53,17 @@ BARE_PLACEHOLDER_RE = re.compile(r"\bREPLACE(?:_[A-Z]+)*\b")
# The previous pattern required ``type`` to be the first and only attribute, so
# blocks carrying a CSP ``nonce``, an ``id`` or ``data-*`` attributes, or an
# unquoted type value were skipped without validation.
+#
+# The attribute group is a small tokenizer, not a plain ``[^>]*``: it consumes a
+# double-quoted value, a single-quoted value, or a run of characters that is
+# neither a quote nor ``>``. A ``[^>]*`` scan ends the tag at the first ``>`` it
+# sees, quoted or not, so an attribute value containing ``>`` (``data-cond="a>b"``,
+# a templated nonce) truncated the tag early and fed the remainder of the
+# attributes plus the real body to the JSON parser as garbage. Treating a quoted
+# span as atomic keeps an embedded ``>`` from ending the tag prematurely.
+_ATTRS_RE = r'(?:"[^"]*"|\'[^\']*\'|[^">])*'
SCRIPT_TAG_RE = re.compile(
- r"<script\b([^>]*)>(.*?)</script\s*>", re.DOTALL | re.IGNORECASE
+ r"<script\b(" + _ATTRS_RE + r")>(.*?)</script\s*>", re.DOTALL | re.IGNORECASE
)
LD_JSON_TYPE_RE = re.compile(
r"""(?:^|\s)type\s*=\s*"""
diff --git a/tests/test_schema_hook_detection.py b/tests/test_schema_hook_detection.py
index 23ee639..6dc35e4 100644
--- a/tests/test_schema_hook_detection.py
+++ b/tests/test_schema_hook_detection.py
@@ -153,3 +153,68 @@ def test_foreign_context_is_still_reported(tmp_path: Path) -> None:
result = _run(tmp_path, "page.html", head)
assert result.returncode == 1
assert "@context should be" in result.stdout
+
+
+# --- tokenizer regressions (a quoted attribute value may contain ">") ------
+
+
+def test_two_plain_ldjson_blocks_are_both_detected(tmp_path: Path) -> None:
+ head = (
+ f'<script type="application/ld+json">{VALID}</script>'
+ f'<script type="application/ld+json">{RETIRED}</script>'
+ )
+ result = _run(tmp_path, "page.html", head)
+ assert result.returncode == 2
+ assert "Block 2" in result.stdout
+ assert "ClaimReview" in result.stdout
+
+
+def test_block_with_nonce_and_id_is_validated(tmp_path: Path) -> None:
+ head = f'<script id="ld-schema" type="application/ld+json" nonce="r4nd0m">{RETIRED}</script>'
+ result = _run(tmp_path, "page.html", head)
+ assert result.returncode == 2
+ assert "ClaimReview" in result.stdout
+
+
+def test_attribute_value_containing_angle_bracket_is_detected(tmp_path: Path) -> None:
+ """A ``[^>]*`` attribute scan ends the tag at the embedded ">", truncating
+ the real JSON-LD body. At the pre-tokenizer PR head this exited 1 (Invalid
+ JSON) instead of recognizing and validating the block.
+ """
+ head = f'<script type="application/ld+json" data-cond="a>b">{VALID}</script>'
+ result = _run(tmp_path, "page.html", head)
+ assert result.returncode == 0
+ assert result.stdout == ""
+
+
+def test_jsx_json_stringify_inside_ldjson_script_is_not_flagged(tmp_path: Path) -> None:
+ head = '<script type="application/ld+json">{JSON.stringify(schema)}</script>'
+ result = _run(tmp_path, "page.jsx", head)
+ assert result.returncode == 0
+ assert result.stdout == ""
+
+
+def test_renal_replacement_therapy_string_is_not_flagged(tmp_path: Path) -> None:
+ head = (
+ '<script type="application/ld+json">'
+ '{"@context":"https://schema.org","@type":"MedicalTherapy",'
+ '"name":"Renal replacement therapy"}'
+ "</script>"
+ )
+ result = _run(tmp_path, "page.html", head)
+ assert result.returncode == 0
+ assert result.stdout == ""
+
+
+def test_top_level_graph_is_detected(tmp_path: Path) -> None:
+ head = (
+ '<script type="application/ld+json">'
+ '{"@context":"https://schema.org","@graph":['
+ '{"@type":"Organization","name":"X"},'
+ f"{RETIRED}"
+ "]}"
+ "</script>"
+ )
+ result = _run(tmp_path, "page.html", head)
+ assert result.returncode == 2
+ assert "ClaimReview" in result.stdout