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(parse-html): detect rel="canonical"/"alternate" case-insensitively
Agrici Daniel28bf1248f53d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ac56615..c53a1f4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0executive summary's critical-issues box or in the full-audit categoryfindings; the "Info" prefix/badge now appears only when the finding is adict that carries an explicit `severity`.+- `parse_html.py` now detects `rel="canonical"` and `rel="alternate"`+ (hreflang) `<link>` tags case-insensitively, so `rel="Alternate"` or+ `REL="Canonical"` are no longer silently dropped. Credit to #269 for the+ report that prompted this investigation.## [2.2.6] - 2026-09-10diff --git a/scripts/parse_html.py b/scripts/parse_html.pyindex 3674e4b..78ae77e 100755--- a/scripts/parse_html.py+++ b/scripts/parse_html.py@@ -45,6 +45,22 @@ _EWWW_CLASSES = {"lazyload-eio", "lazyloaded-eio"}_GENERIC_LAZY_CLASSES = {"lazyload", "lazyloaded", "lazy", "lazy-loaded"}+def _has_rel_token(tag, token: str) -> bool:+ """Case-insensitively check whether a tag's ``rel`` attribute carries ``token``.++ bs4 treats ``rel`` as a multi-valued attribute for ``<a>`` and ``<link>``+ tags, splitting it on whitespace into a list. Both the attribute *name*+ (``REL=``) and the surrounding tag name are lower-cased by the underlying+ HTML parser, but the attribute *value* is preserved verbatim, so+ ``rel="Alternate"`` or ``rel="CANONICAL"`` never matched an exact,+ lower-case comparison such as ``soup.find("link", rel="canonical")``.+ """+ rel = tag.get("rel", [])+ if isinstance(rel, str):+ rel = rel.split()+ return any(isinstance(value, str) and value.lower() == token for value in rel or [])++def _detect_lazy_method(img) -> str:"""Return a coarse classification of the image's lazy-loading mechanism.@@ -130,12 +146,16 @@ def parse_html(html: str, base_url: Optional[str] = None) -> dict:result["twitter_card"][name] = content# Canonical- canonical = soup.find("link", rel="canonical")+ canonical = next(+ (link for link in soup.find_all("link") if _has_rel_token(link, "canonical")), None+ )if canonical:result["canonical"] = canonical.get("href")# Hreflang- for link in soup.find_all("link", rel="alternate"):+ for link in soup.find_all("link"):+ if not _has_rel_token(link, "alternate"):+ continuehreflang = link.get("hreflang")if hreflang:result["hreflang"].append({diff --git a/tests/test_parse_html_rel_case.py b/tests/test_parse_html_rel_case.pynew file mode 100644index 0000000..a10d3f2--- /dev/null+++ b/tests/test_parse_html_rel_case.py@@ -0,0 +1,95 @@+"""+Tests for case-insensitive `rel` detection in scripts/parse_html.py.++Background: `soup.find("link", rel="canonical")` and+`soup.find_all("link", rel="alternate")` compare bs4's parsed `rel` values+with an exact, lower-case string. The underlying HTML parser lower-cases tag+and attribute *names* (so `REL="..."` is read as the `rel` attribute), but it+preserves the attribute *value* verbatim, so `rel="Alternate"` or+`REL="Canonical"` never matched and both the canonical link and every+hreflang alternate using mixed-case `rel` were silently dropped.+"""+import sys+from pathlib import Path++# Make scripts/ importable without requiring it to be a package+REPO_ROOT = Path(__file__).resolve().parent.parent+sys.path.insert(0, str(REPO_ROOT / "scripts"))++from parse_html import parse_html # noqa: E402+++def test_lowercase_rel_canonical_and_alternate_still_work():+ """Baseline: the existing lower-case forms are unaffected by the fix."""+ html = (+ "<html><head>"+ '<link rel="canonical" href="https://example.com/page">'+ '<link rel="alternate" hreflang="en-US" href="https://example.com/en">'+ "</head></html>"+ )+ result = parse_html(html)+ assert result["canonical"] == "https://example.com/page"+ assert result["hreflang"] == [{"lang": "en-US", "href": "https://example.com/en"}]+++def test_titlecase_rel_alternate_is_detected():+ html = (+ "<html><head>"+ '<link href="https://example.com/en" hreflang="en-US" rel="Alternate">'+ "</head></html>"+ )+ result = parse_html(html)+ assert result["hreflang"] == [{"lang": "en-US", "href": "https://example.com/en"}]+++def test_uppercase_rel_attribute_name_and_titlecase_canonical_is_detected():+ html = '<html><head><link REL="Canonical" href="https://example.com/page"></head></html>'+ result = parse_html(html)+ assert result["canonical"] == "https://example.com/page"+++def test_uppercase_rel_value_alternate_is_detected():+ html = (+ "<html><head>"+ '<link rel="ALTERNATE" hreflang="fr" href="https://example.com/fr">'+ "</head></html>"+ )+ result = parse_html(html)+ assert result["hreflang"] == [{"lang": "fr", "href": "https://example.com/fr"}]+++def test_mixed_case_rel_attribute_order_does_not_matter():+ """`rel` before or after `hreflang`/`href` must both be detected."""+ html = (+ "<html><head>"+ '<link hreflang="de" href="https://example.com/de" rel="Alternate">'+ '<link rel="Alternate" hreflang="es" href="https://example.com/es">'+ "</head></html>"+ )+ result = parse_html(html)+ assert {"lang": "de", "href": "https://example.com/de"} in result["hreflang"]+ assert {"lang": "es", "href": "https://example.com/es"} in result["hreflang"]+++def test_self_closing_mixed_case_link_tags_are_detected():+ html = (+ "<html><head>"+ '<link rel="Canonical" href="https://example.com/page" />'+ '<link rel="Alternate" hreflang="en" href="https://example.com/en" />'+ "</head></html>"+ )+ result = parse_html(html)+ assert result["canonical"] == "https://example.com/page"+ assert result["hreflang"] == [{"lang": "en", "href": "https://example.com/en"}]+++def test_lowercase_rel_still_ignores_unrelated_link_types():+ html = (+ "<html><head>"+ '<link rel="stylesheet" href="https://example.com/style.css">'+ '<link rel="Preload" href="https://example.com/font.woff2">'+ "</head></html>"+ )+ result = parse_html(html)+ assert result["canonical"] is None+ assert result["hreflang"] == []