Skip to content

Truly independent web browser

LibWeb: Drop ordinary CSS declarations with empty values

sideshowbarkere7be94b33729
diff --git a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
index fa1dfbde2ba..de58911fa39 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
@@ -6057,6 +6057,9 @@ fn parse_css_value_after_substitution_scan(
} else {
values
};
+ if values.iter().all(ComponentValue::is_whitespace) {
+ return ParseOutcome::Invalid;
+ }
if property_is_shorthand(property_id) {
let outcome = parse_grid_property(context, property_id, values);
if !matches!(outcome, ParseOutcome::NotHandled) {
diff --git a/Libraries/LibWeb/Rust/src/layout/generated_content.rs b/Libraries/LibWeb/Rust/src/layout/generated_content.rs
index ef4301e6623..17ea3c5ae9b 100644
--- a/Libraries/LibWeb/Rust/src/layout/generated_content.rs
+++ b/Libraries/LibWeb/Rust/src/layout/generated_content.rs
@@ -255,7 +255,10 @@ fn quote_string<'a>(quotes: &QuotesData<'a>, open: bool, depth: u32) -> &'a [u16
},
QuotesData::Specified(values) => {
// If the depth is greater than the number of pairs, the last pair is repeated.
- let level = (depth as usize).min(values.len() / 2 - 1);
+ let Some(last_pair) = (values.len() / 2).checked_sub(1) else {
+ return &[];
+ };
+ let level = (depth as usize).min(last_pair);
let quote = &values[level * 2 + usize::from(!open)];
match quote.optional_data() {
Some(StyleValueData::String { string, .. }) => string.units(),
diff --git a/Tests/LibWeb/Text/expected/empty-declaration-value.txt b/Tests/LibWeb/Text/expected/empty-declaration-value.txt
new file mode 100644
index 00000000000..60212bc889b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/empty-declaration-value.txt
@@ -0,0 +1,22 @@
+display: -> false
+display: -> false
+display:/**/ -> false
+display: !important -> false
+quotes: -> false
+quotes: -> false
+quotes:/**/ -> false
+quotes: !important -> false
+list-style: -> false
+list-style: -> false
+list-style:/**/ -> false
+list-style: !important -> false
+text-underline-position: -> false
+text-underline-position: -> false
+text-underline-position:/**/ -> false
+text-underline-position: !important -> false
+--empty: -> true
+--empty: -> true
+--empty:/**/ -> true
+--empty: !important -> true
+flex
+inline
diff --git a/Tests/LibWeb/Text/input/empty-declaration-value.html b/Tests/LibWeb/Text/input/empty-declaration-value.html
new file mode 100644
index 00000000000..69bab929dee
--- /dev/null
+++ b/Tests/LibWeb/Text/input/empty-declaration-value.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<span id="target"></span>
+<script>
+ test(() => {
+ for (const property of ["display", "quotes", "list-style", "text-underline-position", "--empty"]) {
+ for (const value of ["", " ", "/**/", " !important"])
+ println(`${property}:${value} -> ${CSS.supports(property + ":" + value)}`);
+ }
+ target.style.cssText = "display: flex; display: !important";
+ println(getComputedStyle(target).display);
+ target.style.cssText = "--empty: ; display: flex; display: var(--empty)";
+ println(getComputedStyle(target).display);
+ });
+</script>