LibWeb: Don't crash when an unknown property begins with a single dash

This commit is contained in:
Gingeh 2025-07-19 21:09:37 +10:00 committed by Andreas Kling
commit f38e07e0c5
Notes: github-actions[bot] 2025-07-20 06:56:21 +00:00
3 changed files with 184 additions and 1 deletions

View file

@ -1622,7 +1622,7 @@ Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& dec
property_id = PropertyID::Custom;
} else if (has_ignored_vendor_prefix(property_name)) {
return {};
} else if (!property_name.bytes_as_string_view().starts_with('-')) {
} else {
dbgln_if(CSS_PARSER_DEBUG, "Unrecognized CSS property '{}'", property_name);
return {};
}

View file

@ -0,0 +1,79 @@
Harness status: OK
Found 73 tests
53 Pass
20 Fail
Pass no variable
Pass variable
Pass single char variable
Pass single char '-' variable
Pass no char variable
Fail white space value (single space)
Fail white space value (double space)
Pass overwrite
Fail can overwrite with no value
Fail can overwrite with space value
Pass case sensetivity
Pass case sensetivity2
Pass parsing three dashes at start of variable
Pass parsing multiple dashes with one dash at start of variable
Pass leading white space (single space)
Pass middle white space (single space)
Pass trailing white space (single space)
Pass leading white space (double space) 2
Pass middle white space (double space) 2
Pass trailing white space (double space) 2
Pass !important
Fail !important 2
Fail !important (with space)
Pass no variable (Computed Style)
Pass variable (Computed Style)
Pass single char variable (Computed Style)
Pass single char '-' variable (Computed Style)
Pass no char variable (Computed Style)
Fail white space value (single space) (Computed Style)
Fail white space value (double space) (Computed Style)
Pass overwrite (Computed Style)
Fail can overwrite with no value (Computed Style)
Fail can overwrite with space value (Computed Style)
Pass case sensetivity (Computed Style)
Pass case sensetivity2 (Computed Style)
Pass parsing three dashes at start of variable (Computed Style)
Pass parsing multiple dashes with one dash at start of variable (Computed Style)
Pass leading white space (single space) (Computed Style)
Pass middle white space (single space) (Computed Style)
Pass trailing white space (single space) (Computed Style)
Pass leading white space (double space) 2 (Computed Style)
Pass middle white space (double space) 2 (Computed Style)
Pass trailing white space (double space) 2 (Computed Style)
Pass !important (Computed Style)
Fail !important 2 (Computed Style)
Fail !important (with space) (Computed Style)
Pass no variable (Cascading)
Pass variable (Cascading)
Pass single char variable (Cascading)
Pass single char '-' variable (Cascading)
Pass no char variable (Cascading)
Fail white space value (single space) (Cascading)
Fail white space value (double space) (Cascading)
Pass overwrite (Cascading)
Fail can overwrite with no value (Cascading)
Fail can overwrite with space value (Cascading)
Pass case sensetivity (Cascading)
Pass case sensetivity2 (Cascading)
Pass parsing three dashes at start of variable (Cascading)
Pass parsing multiple dashes with one dash at start of variable (Cascading)
Pass leading white space (single space) (Cascading)
Pass middle white space (single space) (Cascading)
Pass trailing white space (single space) (Cascading)
Pass leading white space (double space) 2 (Cascading)
Pass middle white space (double space) 2 (Cascading)
Pass trailing white space (double space) 2 (Cascading)
Pass !important (Cascading)
Fail !important 2 (Cascading)
Fail !important (with space) (Cascading)
Pass basic CSSOM.setProperty
Fail CSSOM.setProperty with space 1
Fail CSSOM.setProperty with space 2
Pass CSSOM.setProperty with space 3

View file

@ -0,0 +1,104 @@
<!DOCTYPE html>
<html>
<head>
<title>variable-definition: get variable value using getPropertyValue</title>
<meta rel="author" title="Kevin Babbitt">
<meta rel="author" title="Greg Whitworth">
<link rel="author" title="Microsoft Corporation" href="http://microsoft.com" />
<link rel="help" href="http://www.w3.org/TR/css-variables-1/#using-variables">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
"use strict";
let templates = [
{ varName:"--var", expectedValue:"", style:"", testName:"no variable"},
{ varName:"--var", expectedValue:"value", style:"--var:value", testName:"variable"},
{ varName:"--v", expectedValue:"value", style:"--v:value", testName:"single char variable"},
{ varName:"---", expectedValue:"value", style:"---:value", testName:"single char '-' variable"},
{ varName:"--", expectedValue:"", style:"--:value", testName:"no char variable"},
{ varName:"--var", expectedValue:" ", style:"--var: ", testName:"white space value (single space)"},
{ varName:"--var", expectedValue:" ", style:"--var: ", testName:"white space value (double space)"},
{ varName:"--var", expectedValue:"value2", style:"--var:value1; --var:value2", testName:"overwrite"},
{ varName:"--var", expectedValue:" ", style:"--var:value;--var:;", testName:"can overwrite with no value"},
{ varName:"--var", expectedValue:" ", style:"--var:value;--var: ;", testName:"can overwrite with space value"},
{ varName:"--var", expectedValue:"value1", style:"--var:value1; --Var:value2", testName:"case sensetivity"},
{ varName:"--Var", expectedValue:"value2", style:"--var:value1; --Var:value2", testName:"case sensetivity2"},
{ varName:"---var", expectedValue:"value", style:"---var:value;", testName:"parsing three dashes at start of variable"},
{ varName:"-var4" , expectedValue:"", style:"-var4:value3", testName:"parsing multiple dashes with one dash at start of variable"},
{ varName:"--var", expectedValue:"value", style:"--var: value", testName:" leading white space (single space)"},
{ varName:"--var", expectedValue:"value1 value2", style:"--var:value1 value2", testName:" middle white space (single space)"},
{ varName:"--var", expectedValue:"value", style:"--var:value ", testName:" trailing white space (single space)"},
{ varName:"--var", expectedValue:"value", style:"--var: value", testName:" leading white space (double space) 2"},
{ varName:"--var", expectedValue:"value1 value2", style:"--var:value1 value2",testName:" middle white space (double space) 2"},
{ varName:"--var", expectedValue:"value", style:"--var:value ", testName:" trailing white space (double space) 2"},
{ varName:"--var", expectedValue:"value1", style:"--var:value1 !important;", testName:"!important"},
{ varName:"--var", expectedValue:"value1", style:"--var:value1!important;--var:value2;", testName:"!important 2"},
{ varName:"--var", expectedValue:"value1", style:"--var:value1 !important;--var:value2;", testName:"!important (with space)"}
];
templates.forEach(function (template) {
test( function () {
let div = document.createElement("div");
div.style.cssText = template.style;
document.body.appendChild(div);
let value = div.style.getPropertyValue(template.varName);
assert_equals(value, template.expectedValue, "Expected Value should match actual value");
document.body.removeChild(div);
}, template.testName);
});
templates.forEach(function (template) {
test( function () {
let div = document.createElement("div");
div.style.cssText = template.style;
document.body.appendChild(div);
let computedStyle = window.getComputedStyle(div);
let value = computedStyle.getPropertyValue(template.varName);
assert_equals(value, template.expectedValue, "Expected Value should match actual value");
document.body.removeChild(div);
}, template.testName +" (Computed Style)");
});
templates.forEach(function (template) {
test( function () {
let div = document.createElement("div");
div.style.cssText = template.style;
document.body.appendChild(div);
let divChild = document.createElement("div");
div.appendChild(divChild);
let computedStyle = window.getComputedStyle(divChild);
let value = computedStyle.getPropertyValue(template.varName);
assert_equals(value, template.expectedValue, "Expected Value should match actual value");
document.body.removeChild(div);
}, template.testName +" (Cascading)");
});
let template2 = [
{ varToSet:"--varUnique", setValue:"green", varNameForRetrieval:"--varUnique", expectedValue:"green", testName:"basic CSSOM.setProperty"},
{ varToSet:"--varUnique2 ", setValue:"green", varNameForRetrieval:"--varUnique2 ", expectedValue:"", testName:"CSSOM.setProperty with space 1"},
{ varToSet:"--varUnique3 name", setValue:"green", varNameForRetrieval:"--varUnique3 name", expectedValue:"", testName:"CSSOM.setProperty with space 2"},
{ varToSet:"--varUnique4 name", setValue:"green", varNameForRetrieval:"--varUnique4", expectedValue:"", testName:"CSSOM.setProperty with space 3"},
];
template2.forEach(function (template) {
test( function () {
let div = document.createElement("div");
div.style.setProperty(template.varToSet, template.setValue);
document.body.appendChild(div);
let computedStyle = window.getComputedStyle(div);
let value = computedStyle.getPropertyValue(template.varNameForRetrieval);
assert_equals(value, template.expectedValue, "Expected Value should match actual value");
document.body.removeChild(div);
}, template.testName);
});
</script>
</body>
</html>