fix(id): escape values assigned through the value setter - #326
Conversation
ID had no value setter, so a programmatically assigned id value was emitted verbatim instead of escaped. ClassName has escaped assigned values since 2018; mirror the same setter on ID.
|
Thanks. This is a real gap, and reusing I ran the branch against This fixes more than the description saysOn an ID parsed with an escape, reassigning const id = parser().astSync('#fo\\o').first.first;
id.value = 'bar';
id.toString(); // main: '#fo\o' branch: '#bar'Your test covers it ( Docs
On the releaseThis changes observable behaviour for existing code: anyone assigning an already-escaped value now gets a double escape. id.value = 'foo\\.bar'; // main: '#foo\.bar' branch: '#foo\\\.bar'That's the same footgun This package sits deep in a lot of dependency trees, so I'd like a second opinion: does minor seem right to you, or would you go major? |
IDdoesn't overridevalue, so assigning toid.valuestores the string as-is andtoString()emits it unescaped.ClassNamehas had an escapingvaluesetter sinced4dda8c5("Escape class name values by default", 2018), butIDnever got the same one, even though class and id selectors are both identifiers and follow the same escaping rules.The result is wrong output for any id value that contains characters needing escapes:
Leading digits, spaces and
#break the same way:#1abc,#a b,#a#b.This adds the same setter
ClassNameuses (cssesc(v, { isIdentifier: true })stored intoraws.value), so id values escape on assignment:The new test mirrors the existing
ClassName#set valuetest.npm testpasses (lint, typecheck, full suite).