Repository navigation
🐛 fix(encoding): read meta declarations whole and fall through - #2155
Merged
Merged
Conversation
The <meta> prescan and the tree pass copied a charset value into a fixed-size buffer before looking it up. A value longer than the buffer was cut, and the remaining prefix was trimmed of whitespace and matched as a label. A value that names no encoding could therefore select one, and a label padded with whitespace could be ignored. parse() and detect() then disagreed with browsers on such pages. The lookup now runs on the whole value as each attribute is read, and the content label stays a span of the value instead of a copy. The lookup already applies the length limit to the trimmed label, so a value that does not name an encoding is ignored and a padded label resolves, as in the WHATWG algorithm.
Merging this PR will not alter performance
Comparing Footnotes
|
The tree pass recorded a meta element's charset attribute and, when that attribute had any value, skipped its content value. The tree-construction rule for meta elements tries content whenever the charset value names no encoding, so a charset of "" or an unknown label hid a valid Content-Type declaration from parse(). The prescan handled an empty charset by reading content, but an unknown label blocked it, so detect() and parse() could disagree on the same meta. The prescan and the tree pass now use the same order per meta element: a charset value that names an encoding wins, otherwise a content value counts when http-equiv is Content-Type. A failing charset attribute no longer hides content in either path. The prescan's own text in the standard lets a failing charset block content, which differs from the tree-construction rule; the tree rule decides what parse() returns, so the prescan follows it too.
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.
The
<meta>encoding detection could pick an encoding that the document does not declare in full. 🌐 It cut longcharsetandcontentvalues before the lookup, so the prefix of a value could name an encoding that the whole value does not. Acharsetthat named no encoding could also hide a validcontentdeclaration, soparse()anddetect()could disagree on the same element. After this change both read each meta element the way the tree-construction rules do.The WHATWG get an encoding step takes the whole label. The tree-construction rule for a meta element tries
charsetfirst, and it triescontentonly whencharsetnames no encoding andhttp-equivisContent-Type. The prescan text would stop at acharsetthat names no encoding. The detector follows the tree rule instead, because the tree rule decides whatparse()returns.Behavior changes
charsetvalue, and thecharset=token incontent, are judged whole. A label padded with whitespace now resolves, and a value that named an encoding only after being cut is ignored.charsetthat names no encoding no longer hides acontentdeclaration on the same element. This applies toparse()anddetect().charsetthat names an encoding still wins overcontent.Fixes #1775.