fix: avoid duplicating escaped characters when parsing styles (#17554)

* fix and test

* changeset

* format

* increment index and escape early instead
pull/17555/head
Tee Ming 1 day ago committed by GitHub
parent 9662010a13
commit 83eb9dac64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: avoid duplicating escaped characters in CSS AST

@ -508,8 +508,12 @@ function read_value(parser) {
if (escaped) {
value += '\\' + char;
escaped = false;
parser.index++;
continue;
} else if (char === '\\') {
escaped = true;
parser.index++;
continue;
} else if (char === quote_mark) {
quote_mark = null;
} else if (char === ')') {

@ -135,4 +135,19 @@ describe('parseCss', () => {
}
}
});
it('parses escaped characters', () => {
const ast = parseCss("div { background: url('./example.png?\\''); }");
assert.equal(ast.type, 'StyleSheet');
assert.equal(ast.children.length, 1);
const rule = ast.children[0];
assert.equal(rule.type, 'Rule');
if (rule.type === 'Rule') {
const declaration = rule.block.children[0];
assert.equal(declaration.type, 'Declaration');
if (declaration.type === 'Declaration') {
assert.equal(declaration.value, "url('./example.png?\\'')");
}
}
});
});

Loading…
Cancel
Save