mirror of https://github.com/sveltejs/svelte
fix: preserve CSS escape sequences when printing selectors (#18667)
Fixes #18664 `print()` was writing selector names back out verbatim. The parser decodes CSS escape sequences when it reads them — `\31` becomes `1`, `\a` becomes a newline — so the printer produced selectors that either failed to re-parse (`#123`) or silently meant something different (`#line\nbreak` turns into a descendant combinator). A small re-escaper (`escape_identifier`) is now used when printing type, class, id, pseudo, attribute and at-rule names. Also fixes a backslash parser bug in the process. --------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/18676/head
parent
fe4a56b0a8
commit
8835003d41
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: preserve CSS escape sequences when printing selectors
|
||||
@ -0,0 +1,25 @@
|
||||
<div></div>
|
||||
|
||||
<style>
|
||||
#\31\32\33 { color: green; }
|
||||
#\31 23 { color: green; }
|
||||
#line\a break { color: green; }
|
||||
#line\a
|
||||
break { color: green; }
|
||||
li\.foo { color: green; }
|
||||
.a\1f642 b { color: green; }
|
||||
.a🙂b { color: green; }
|
||||
#\2d 1foo { color: red; }
|
||||
.a\5c b { color: red; }
|
||||
.a\\b { color: red; }
|
||||
.a\5c q { color: red; }
|
||||
.a\\q { color: red; }
|
||||
.a\5c { color: red; }
|
||||
.a\\ { color: red; }
|
||||
#\5c a { color: red; }
|
||||
[\31 data] { color: red; }
|
||||
:\31 st-child { color: red; }
|
||||
* { color: red; }
|
||||
#id-selector { color: red; }
|
||||
[data-attribute="value"] { color: red; }
|
||||
</style>
|
||||
@ -0,0 +1,83 @@
|
||||
<div></div>
|
||||
|
||||
<style>
|
||||
#\31 23 {
|
||||
color: green;
|
||||
}
|
||||
|
||||
#\31 23 {
|
||||
color: green;
|
||||
}
|
||||
|
||||
#line\a break {
|
||||
color: green;
|
||||
}
|
||||
|
||||
#line\a break {
|
||||
color: green;
|
||||
}
|
||||
|
||||
li\.foo {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.a🙂b {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.a🙂b {
|
||||
color: green;
|
||||
}
|
||||
|
||||
#\2d 1foo {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.a\\b {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.a\\b {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.a\\q {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.a\\q {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.a\\ {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.a\\ {
|
||||
color: red;
|
||||
}
|
||||
|
||||
#\\a {
|
||||
color: red;
|
||||
}
|
||||
|
||||
[\31 data] {
|
||||
color: red;
|
||||
}
|
||||
|
||||
:\31 st-child {
|
||||
color: red;
|
||||
}
|
||||
|
||||
* {
|
||||
color: red;
|
||||
}
|
||||
|
||||
#id-selector {
|
||||
color: red;
|
||||
}
|
||||
|
||||
[data-attribute="value"] {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in new issue