Repository navigation
Conversation
`parser.attribute({ attribute: "href", operator: "=", value: "foo bar",
quoteMark: '"' })` printed as `[href=foo bar]`: the value was neither
quoted nor escaped, though `attr.quoteMark` reported `"`. Passing a quote
mark is the non-deprecated way to construct an attribute with a value, and
the value is unescaped in that form, so the result did not parse back to
the same value. Setting `quoteMark` or calling `setValue()` afterwards
already quoted it.
The constructor now quotes and escapes the value for its quote mark,
unless `raws.value` is given. The parser drops the raw value this adds
when it had none, so parsed attributes keep their original spelling.
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 bug
Passing
quoteMarktoparser.attribute()has no effect on the output:The constructor's deprecation message makes this the supported form ("The value should be unescaped now"). But the value is printed as given, neither quoted nor escaped, so
[href=foo bar]does not parse back to the same value.quoteMark: nullbehaves the same way:foo baris printed with its space unescaped. Evenvalue: "foo"withquoteMark: '"'comes out unquoted, as[href=foo].Doing the same after construction works, because the
quoteMarksetter andsetValue()both call_syncRawValue(). The constructor sets_constructedonly after the options are assigned, so that call never happens.The fix
At the end of the constructor, if there is a string value and no
raws.value, call_syncRawValue(). The deprecated form withoutquoteMarkalways setsraws.valueitself, so it is unaffected.The parser creates attributes through the same constructor and leaves
raws.valueunset when the spelling needs nothing kept. It now removes the raw value the constructor adds in that case, so parsed attributes keep their original spelling. This matters for non-standard values such as[x=@{v}], which would otherwise be escaped.Verification
Six tests in
attributes.mjscover double and single quotes, a value containing its own quote mark, andnullwith and without a space. Each checks the output and that it parses back to the same value and quote mark. Five of them fail onmain. The sixth,nullwith a plain identifier, passes either way. Two more tests check that an explicitraws.valuewins, and that parsed attributes, including Less, print and clone unchanged.npm testis green: lint, type check, and coverage gates.