Skip to content

Read uppercase attribute names the way a browser does - #123

Merged
only-cli merged 1 commit into
only-cli:mainfrom
kevin9327:read-uppercase-attribute-names
Oct 5, 2026
Merged

only-cli merged 1 commit into
only-cli:mainfrom
kevin9327:read-uppercase-attribute-names

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

HTML attribute names are case-insensitive, but linkedom keeps them exactly as written. So on a page that uses uppercase markup, every getAttribute and attribute selector in distill missed:

  • <A HREF="/x"> lost its link and printed as plain text
  • <INPUT TYPE="hidden"> was numbered as a visible text field
  • STYLE="display:none", HIDDEN and Aria-Hidden="true" content leaked into the view and into raw

This adds lowerAttributeNames(document), called once right after parseHTML in distill() and cleanDocument(), so the rest of the code sees names the way a browser would. If an attribute is written twice in different cases, the first one wins, which is also what a browser does.

How I verified it:

  • New test in tests/distill.test.js ("attribute names are matched case-insensitively, as HTML does"). It fails on main and passes with this change.
  • npm test: 320/321 pass. The one failure ("a reddit short or share link is read as the feed of the post it redirects to") fails the same way on unmodified main in my environment. My sandbox blocks that URL as private, so it isn't related to this change.

Not covered here: an uppercase style value such as style="DISPLAY:NONE" still gets through. That's a separate check and I left it out to keep this PR small.

HTML attribute names are case-insensitive, but linkedom keeps them as written. On a page written as <A HREF>, <INPUT TYPE="hidden"> or <P STYLE="display:none">, every getAttribute and attribute selector missed: the link had no href and printed as plain text, the hidden csrf input was numbered as a text field, and hidden content showed up in the view and in raw. Lowercasing attribute names once after parsing fixes all of them in one place.
@only-cli
only-cli merged commit 8e22ec2 into only-cli:main Oct 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants