Skip to content

Commit e674bc5

Browse files
committed
Disallow { in standard properties to avoid ambiguity in nested rules
w3c/csswg-drafts#9317
1 parent a8b7ea0 commit e674bc5

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/declaration.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::error::{ParserError, PrinterError};
88
use crate::parser::ParserOptions;
99
use crate::printer::Printer;
1010
use crate::properties::box_shadow::BoxShadowHandler;
11+
use crate::properties::custom::CustomPropertyName;
1112
use crate::properties::masking::MaskHandler;
1213
use crate::properties::{
1314
align::AlignHandler,
@@ -456,15 +457,22 @@ pub(crate) fn parse_declaration<'i, 't>(
456457
important_declarations: &mut DeclarationList<'i>,
457458
options: &ParserOptions<'_, 'i>,
458459
) -> Result<(), cssparser::ParseError<'i, ParserError<'i>>> {
459-
let property = input.parse_until_before(Delimiter::Bang, |input| {
460-
Property::parse(PropertyId::from(CowArcStr::from(name)), input, options)
461-
})?;
460+
// Stop if we hit a `{` token in a non-custom property to
461+
// avoid ambiguity between nested rules and declarations.
462+
// https://github.com/w3c/csswg-drafts/issues/9317
463+
let property_id = PropertyId::from(CowArcStr::from(name));
464+
let mut delimiters = Delimiter::Bang;
465+
if !matches!(property_id, PropertyId::Custom(CustomPropertyName::Custom(..))) {
466+
delimiters = delimiters | Delimiter::CurlyBracketBlock;
467+
}
468+
let property = input.parse_until_before(delimiters, |input| Property::parse(property_id, input, options))?;
462469
let important = input
463470
.try_parse(|input| {
464471
input.expect_delim('!')?;
465472
input.expect_ident_matching("important")
466473
})
467474
.is_ok();
475+
input.expect_exhausted()?;
468476
if important {
469477
important_declarations.push(property);
470478
} else {

src/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22428,6 +22428,44 @@ mod tests {
2242822428
"#},
2242922429
);
2243022430

22431+
nesting_test(
22432+
r#"
22433+
div {
22434+
color: blue;
22435+
22436+
button:focus {
22437+
color: red;
22438+
}
22439+
}
22440+
"#,
22441+
indoc! {r#"
22442+
div {
22443+
color: #00f;
22444+
}
22445+
22446+
div button:focus {
22447+
color: red;
22448+
}
22449+
"#},
22450+
);
22451+
nesting_test(
22452+
r#"
22453+
div {
22454+
color: blue;
22455+
22456+
--button:focus {
22457+
color: red;
22458+
}
22459+
}
22460+
"#,
22461+
indoc! {r#"
22462+
div {
22463+
color: #00f;
22464+
--button: focus { color: red; };
22465+
}
22466+
"#},
22467+
);
22468+
2243122469
nesting_test_no_targets(
2243222470
r#"
2243322471
.foo {

0 commit comments

Comments
 (0)