Skip to content

Commit 478c565

Browse files
committed
fix: Ignored !important that has insignificant whitespace after it
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent 9ee9577 commit 478c565

File tree

9 files changed

+36
-3
lines changed

9 files changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
- Update `selectors` to `0.30`.
1414
- Update `html5ever` to `0.35`.
1515

16+
### Fixed
17+
18+
- Ignored `!important` that has insignificant whitespace after it.
19+
1620
### Performance
1721

1822
- Use interned string to compare `style` element name.
23+
- Only check the value suffix for `!important`.
1924

2025
## [0.15.0] - 2025-06-17
2126

bindings/c/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
- Update `selectors` to `0.30`.
99
- Update `html5ever` to `0.35`.
1010

11+
### Fixed
12+
13+
- Ignored `!important` that has insignificant whitespace after it.
14+
1115
### Performance
1216

1317
- Use interned string to compare `style` element name.
18+
- Only check the value suffix for `!important`.
1419

1520
## [0.15.0] - 2025-06-21
1621

bindings/java/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
- Update `selectors` to `0.30`.
99
- Update `html5ever` to `0.35`.
1010

11+
### Fixed
12+
13+
- Ignored `!important` that has insignificant whitespace after it.
14+
1115
### Performance
1216

1317
- Use interned string to compare `style` element name.
18+
- Only check the value suffix for `!important`.
1419

1520
## 0.15.0 - 2025-06-29
1621

bindings/javascript/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
### Fixed
1212

1313
- Expose `StylesheetCache` interface, `cache` config option, and `version` function.
14+
- Ignored `!important` that has insignificant whitespace after it.
1415

1516
### Performance
1617

1718
- Use interned string to compare `style` element name.
19+
- Only check the value suffix for `!important`.
1820

1921
## [0.15.0] - 2025-06-24
2022

bindings/python/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
### Fixed
1212

1313
- Set `3.9` in `requires-python` key in `pyproject.toml`.
14+
- Ignored `!important` that has insignificant whitespace after it.
1415

1516
### Performance
1617

1718
- Use interned string to compare `style` element name.
19+
- Only check the value suffix for `!important`.
1820

1921
## [0.15.0] - 2025-06-17
2022

bindings/ruby/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
- Update `selectors` to `0.30`.
88
- Update `html5ever` to `0.35`.
99

10+
### Fixed
11+
12+
- Ignored `!important` that has insignificant whitespace after it.
13+
1014
### Performance
1115

1216
- Use interned string to compare `style` element name.
17+
- Only check the value suffix for `!important`.
1318

1419
## [0.15.2] - 2025-06-24
1520

css-inline/src/html/serializer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ fn merge_styles<Wr: Write>(
495495
// New rules will not override old ones unless they are marked as `!important`
496496
for (property, (_, value)) in new_styles {
497497
match (
498-
value.strip_suffix("!important"),
498+
value.trim_end().strip_suffix("!important"),
499499
declarations_buffer
500500
.iter_mut()
501501
.take(parsed_declarations_count)

css-inline/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ impl<'a> CSSInliner<'a> {
462462
match element_styles.entry(name.as_ref()) {
463463
indexmap::map::Entry::Occupied(mut entry) => {
464464
match (
465-
value.ends_with("!important"),
466-
entry.get().1.ends_with("!important"),
465+
value.trim_end().ends_with("!important"),
466+
entry.get().1.trim_end().ends_with("!important"),
467467
) {
468468
// Equal importance; the higher specificity wins.
469469
(false, false) | (true, true) => {

css-inline/tests/test_inlining.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ fn important() {
246246
)
247247
}
248248

249+
#[test]
250+
fn important_with_space_at_the_end() {
251+
assert_inlined!(
252+
style = "h1 { color: blue !important ; }",
253+
body = r#"<h1 style="color: red;">Big Text</h1>"#,
254+
expected = r#"<h1 style="color: blue">Big Text</h1>"#
255+
)
256+
}
257+
249258
#[test]
250259
fn important_no_rule_exists() {
251260
// `!important` rules should override existing inline styles

0 commit comments

Comments
 (0)