Repository navigation
Read uppercase attribute names the way a browser does - #123
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTML attribute names are case-insensitive, but linkedom keeps them exactly as written. So on a page that uses uppercase markup, every
getAttributeand 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 fieldSTYLE="display:none",HIDDENandAria-Hidden="true"content leaked into the view and into rawThis adds
lowerAttributeNames(document), called once right afterparseHTMLindistill()andcleanDocument(), 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:
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.