From bf37f3400e22a53126c8e12eadb6857ee627c483 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 25 Jun 2025 11:43:14 +0100 Subject: [PATCH] LibWeb: Don't treat "--" as a valid custom property name This is reserved for future use by CSS. --- Libraries/LibWeb/CSS/PropertyName.h | 10 +++++++++- .../css-variables/variable-empty-name-reserved.txt | 6 ++++++ .../css-variables/variable-empty-name-reserved.html | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-variables/variable-empty-name-reserved.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-variables/variable-empty-name-reserved.html diff --git a/Libraries/LibWeb/CSS/PropertyName.h b/Libraries/LibWeb/CSS/PropertyName.h index 6bf7d5f8c18..3318fcf1628 100644 --- a/Libraries/LibWeb/CSS/PropertyName.h +++ b/Libraries/LibWeb/CSS/PropertyName.h @@ -11,11 +11,19 @@ namespace Web::CSS { +static bool is_invalid_custom_property_name_string(StringView string) +{ + // https://drafts.csswg.org/css-variables-2/#typedef-custom-property-name + // The production corresponds to this: it’s defined as any + // (a valid identifier that starts with two dashes), except -- itself, which is reserved for future use by CSS. + return string == "--"sv; +} + // https://drafts.css-houdini.org/css-typed-om-1/#custom-property-name-string static bool is_a_custom_property_name_string(StringView string) { // A string is a custom property name string if it starts with two dashes (U+002D HYPHEN-MINUS), like --foo. - return string.starts_with("--"sv); + return string.starts_with("--"sv) && !is_invalid_custom_property_name_string(string); } } diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-variables/variable-empty-name-reserved.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-variables/variable-empty-name-reserved.txt new file mode 100644 index 00000000000..8391c5e536c --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-variables/variable-empty-name-reserved.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass -- is a reserved property name \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-variables/variable-empty-name-reserved.html b/Tests/LibWeb/Text/input/wpt-import/css/css-variables/variable-empty-name-reserved.html new file mode 100644 index 00000000000..5ece96b9167 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-variables/variable-empty-name-reserved.html @@ -0,0 +1,13 @@ + + + + + +-- is a reserved property name + + +