Skip to content

Commit 3bdefdc

Browse files
committed
Ensure custom property names are escaped
Fixes parcel-bundler#125
1 parent 53e74f3 commit 3bdefdc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10187,6 +10187,7 @@ mod tests {
1018710187
minify_test(".foo { color: var(--color, #ffff00); }", ".foo{color:var(--color,#ff0)}");
1018810188
minify_test(".foo { color: var(--color, rgb(var(--red), var(--green), 0)); }", ".foo{color:var(--color,rgb(var(--red),var(--green),0))}");
1018910189
minify_test(".foo { --test: .5s; }", ".foo{--test:.5s}");
10190+
minify_test(".foo { --theme-sizes-1\\/12: 2 }", ".foo{--theme-sizes-1\\/12:2}");
1019010191

1019110192
prefix_test(r#"
1019210193
.foo {

src/properties/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,15 @@ macro_rules! define_properties {
417417
};
418418
}
419419

420+
macro_rules! write_important {
421+
() => {
422+
if important {
423+
dest.whitespace()?;
424+
dest.write_str("!important")?;
425+
}
426+
}
427+
}
428+
420429
let (name, prefix) = match self {
421430
$(
422431
$(#[$meta])*
@@ -435,7 +444,14 @@ macro_rules! define_properties {
435444
)+
436445
Unparsed(unparsed) => (unparsed.property_id.name(), unparsed.property_id.prefix()),
437446
Logical(logical) => (logical.property_id.name(), logical.property_id.prefix()),
438-
Custom(custom) => (custom.name.as_ref(), VendorPrefix::None),
447+
Custom(custom) => {
448+
// Ensure custom property names are escaped.
449+
serialize_name(custom.name.as_ref(), dest)?;
450+
dest.delim(':', false)?;
451+
self.value_to_css(dest)?;
452+
write_important!();
453+
return Ok(())
454+
}
439455
};
440456

441457
macro_rules! write {
@@ -446,10 +462,7 @@ macro_rules! define_properties {
446462
dest.write_str(name)?;
447463
dest.delim(':', false)?;
448464
self.value_to_css(dest)?;
449-
if important {
450-
dest.whitespace()?;
451-
dest.write_str("!important")?;
452-
}
465+
write_important!();
453466
}
454467
}
455468
}

0 commit comments

Comments
 (0)