mirror of https://github.com/sveltejs/svelte
fix: treat CSS attribute selectors as case-insensitive for HTML enumerated attributes (#17712)
Fixes #17207 CSS attribute selectors for HTML enumerated attributes (like `method`, `type`, `dir`, etc.) are supposed to match case-insensitively per the HTML spec. Browsers handle this correctly — `form[method="get"]` matches `<form method="GET">`. But Svelte's CSS pruning was doing a strict case-sensitive comparison, which meant: 1. The selector got incorrectly flagged as unused (no `css_unused_selector` warning was shown when spreads were involved, but the selector was still pruned) 2. The scoping class wasn't applied to the matching element 3. Styles silently disappeared in production builds The fix adds a set of known HTML attributes with case-insensitive enumerated values (sourced from the HTML spec) and uses it during CSS attribute selector matching. The explicit CSS `s` flag still overrides this behavior, as expected. ### Before ```svelte <form method="GET"> <h1>Hello</h1> </form> <style> form[method="get"] h1 { color: red; } /* ^ incorrectly pruned, <h1> not styled */ </style> ``` ### After The selector correctly matches and styles are applied. ### Test plan - Added `attribute-selector-html-case-insensitive` CSS test covering `form[method]` and `input[type]` cases - All 179 existing CSS tests pass - Verified the existing `attribute-selector-case-sensitive` test (using `s` flag) still works correctly - Compiler error tests and validator tests all pass --------- Co-authored-by: Rich Harris <hello@rich-harris.dev> Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/17725/head
parent
6557a0a591
commit
60a425193c
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: treat CSS attribute selectors as case-insensitive for HTML enumerated attributes
|
||||
@ -0,0 +1,11 @@
|
||||
form[method="get"].svelte-xyz h1:where(.svelte-xyz) {
|
||||
color: red;
|
||||
}
|
||||
|
||||
form[method="post"].svelte-xyz h1:where(.svelte-xyz) {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
input[type="text"].svelte-xyz {
|
||||
color: green;
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
<form class="svelte-xyz" method="GET"><h1 class="svelte-xyz">Hello</h1></form> <form class="svelte-xyz" method="POST"><h1 class="svelte-xyz">World</h1></form> <input class="svelte-xyz" type="Text" />
|
||||
@ -0,0 +1,23 @@
|
||||
<form method="GET">
|
||||
<h1>Hello</h1>
|
||||
</form>
|
||||
|
||||
<form method="POST">
|
||||
<h1>World</h1>
|
||||
</form>
|
||||
|
||||
<input type="Text" />
|
||||
|
||||
<style>
|
||||
form[method="get"] h1 {
|
||||
color: red;
|
||||
}
|
||||
|
||||
form[method="post"] h1 {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in new issue