Skip to content

Commit a7e1774

Browse files
committed
fix '~=' selector matching against arbitrary whitespace (sveltejs#4242)
1 parent 2f81365 commit a7e1774

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/compiler/compile/css/Selector.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function apply_selector(blocks: Block[], node: Element, stack: Element[], to_enc
171171
if (ancestor_block.global) {
172172
continue;
173173
}
174-
174+
175175
for (const stack_node of stack) {
176176
if (block_might_apply_to_node(ancestor_block, stack_node) !== BlockAppliesToNode.NotPossible) {
177177
to_encapsulate.push({ node: stack_node, block: ancestor_block });
@@ -256,7 +256,7 @@ function test_attribute(operator, expected_value, case_insensitive, value) {
256256
}
257257
switch (operator) {
258258
case '=': return value === expected_value;
259-
case '~=': return ` ${value} `.includes(` ${expected_value} `);
259+
case '~=': return value.split(/\s/).includes(expected_value);
260260
case '|=': return `${value}-`.startsWith(`${expected_value}-`);
261261
case '^=': return value.startsWith(expected_value);
262262
case '$=': return value.endsWith(expected_value);
@@ -295,7 +295,7 @@ function attribute_matches(node: CssNode, name: string, expected_value: string,
295295

296296
// impossible to find out all combinations
297297
if (current_possible_values.has(UNKNOWN)) return true;
298-
298+
299299
if (prev_values.length > 0) {
300300
const start_with_space = [];
301301
const remaining = [];

0 commit comments

Comments
 (0)