Skip to content

Commit 1077b8e

Browse files
committed
Fix var() fallback color minification context in unparsed values
Preserve parsing context when reading var() fallbacks inside unparsed property token lists, so color-ident minification respects function-level whitelisting instead of being reapplied as top-level parsing. e.g. Added/updated regression tests in test_custom_properties covering: non-whitelisted function: foo(var(--c, blue)) should keep blue,
1 parent 13d9d4b commit 1077b8e

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23389,6 +23389,23 @@ mod tests {
2338923389
".foo { color: var(--color, rgb(var(--red), var(--green), 0)); }",
2339023390
".foo{color:var(--color,rgb(var(--red), var(--green), 0))}",
2339123391
);
23392+
// 非白名单内的函数颜色值保持原状
23393+
minify_test(
23394+
".foo{background: foo(var(--c, blue))}",
23395+
".foo{background:foo(var(--c,blue))}",
23396+
);
23397+
minify_test(
23398+
".foo2{background: linear-gradient(foo(var(--c, blue)), red)}",
23399+
".foo2{background:linear-gradient(foo(var(--c,blue)), red)}",
23400+
);
23401+
minify_test(
23402+
".foo3{background: linear-gradient(var(--c, blue),red)}",
23403+
".foo3{background:linear-gradient(var(--c,#00f),red)}",
23404+
);
23405+
minify_test(
23406+
".foo4{--x: 90px; background: linear-gradient(red var(--x, white), blue)}",
23407+
".foo4{--x:90px;background:linear-gradient(red var(--x,#fff), #00f)}",
23408+
);
2339223409

2339323410
// 非 color 相关的属性颜色值保持原状
2339423411
minify_test(

src/properties/custom.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<'i> TokenList<'i> {
446446
tokens.push(TokenOrValue::Url(Url::parse(input)?));
447447
} else if f == "var" {
448448
let var = input.parse_nested_block(|input| {
449-
let var = Variable::parse(input, options, depth + 1, parse_options.color_ident_mode)?;
449+
let var = Variable::parse(input, options, depth + 1, parse_options)?;
450450
Ok(TokenOrValue::Var(var))
451451
})?;
452452
tokens.push(var);
@@ -1351,17 +1351,12 @@ impl<'i> Variable<'i> {
13511351
input: &mut Parser<'i, 't>,
13521352
options: &ParserOptions<'_, 'i>,
13531353
depth: usize,
1354-
color_ident_mode: ColorIdentMode,
1354+
parse_options: TokenListParseOptions,
13551355
) -> Result<Self, ParseError<'i, ParserError<'i>>> {
13561356
let name = DashedIdentReference::parse_with_options(input, options)?;
13571357

13581358
let fallback = if input.try_parse(|input| input.expect_comma()).is_ok() {
1359-
Some(TokenList::parse_with_color_idents(
1360-
input,
1361-
options,
1362-
depth,
1363-
color_ident_mode,
1364-
)?)
1359+
Some(TokenList::read_token_list(input, options, depth, parse_options)?)
13651360
} else {
13661361
None
13671362
};

0 commit comments

Comments
 (0)