Skip to content

Commit 128775d

Browse files
committed
Discard arbitrary properties with ! at the top-level
Unless it’s part of `!important` at the end
1 parent fa2be75 commit 128775d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

crates/oxide/src/extractor/arbitrary_property_machine.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ impl Machine for ArbitraryPropertyMachine<ParsingValueState> {
231231
return self.restart()
232232
}
233233

234+
// An `!` at the top-level must be followed by "important" *and* be at the end
235+
// otherwise its invalid
236+
Class::Exclamation if self.bracket_stack.is_empty() => {
237+
if cursor.input[cursor.pos..].starts_with(b"!important]") {
238+
cursor.advance_by(10);
239+
240+
return self.done(self.start_pos, cursor);
241+
}
242+
243+
return self.restart()
244+
}
245+
234246
// Everything else is valid
235247
_ => cursor.advance(),
236248
};
@@ -293,6 +305,9 @@ enum Class {
293305
#[bytes(b'/')]
294306
Slash,
295307

308+
#[bytes(b'!')]
309+
Exclamation,
310+
296311
#[bytes(b' ', b'\t', b'\n', b'\r', b'\x0C')]
297312
Whitespace,
298313

@@ -369,6 +384,12 @@ mod tests {
369384
"[background:url(https://example.com?q={[{[([{[[2]]}])]}]})]",
370385
vec!["[background:url(https://example.com?q={[{[([{[[2]]}])]}]})]"],
371386
),
387+
388+
// A property containing `!` at the top-level is invalid
389+
("[color:red!]", vec![]),
390+
391+
// Unless its part of `!important at the end
392+
("[color:red!important]", vec!["[color:red!important]"]),
372393
] {
373394
for wrapper in [
374395
// No wrapper

0 commit comments

Comments
 (0)