Repository navigation
Handle style values containing ; - #370
Open
alphaNumericEntity wants to merge 1 commit into
Open
alphaNumericEntity wants to merge 1 commit into
alphaNumericEntity wants to merge 1 commit into
Conversation
Inline style declarations were split on every `;`, so a value such as `url(data:image/png;base64,...)` or `"a;b"` was cut in two. Reading it returned `url(data:image/png`, and setting any other property rewrote the attribute without the rest of the value. Declarations are now split only on a `;` outside quotes, parentheses and comments.
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.
A
;inside an inline style value cuts the declaration in two. This happens with data URIs (url(data:image/png;base64,...)) and with quoted strings (content: "a;b",font-family: "a;b", serif). Reading the value gives back only the part before the;, and setting any other property rewrites the attribute from that truncated parse, so the rest of the value is lost:The cause is
updateKeysinesm/interface/css-style-declaration.js, which splits the attribute withsplit(/\s*;\s*/). #129 fixed the same problem for:(as inurl(https://...)); this is the;half.The fix replaces the regex split with a small
splitRuleshelper that walks the string once and splits on;only outside quotes, parentheses and/* */comments, skipping backslash-escaped characters. Keys and values are still trimmed as before, so a style string with no quotes, parentheses, backslashes or comments parses exactly as it did.Testing: new cases in
test/interface/css-style-declaration.jscover a data URI (read,length, and the attribute after setting another property),;inside double and single quotes, a stray), a quote inside a comment, and a/*insideurl()(not a comment there). The data URI case fails onmainwithGot instead: url(data:image/png.npm testpasses with coverage unchanged at 100%, andcjs/is regenerated withnpm run cjs.