diff --git a/Userland/Libraries/LibWeb/CSS/CSS.cpp b/Userland/Libraries/LibWeb/CSS/CSS.cpp index fbe04dcf47e..5acace9e786 100644 --- a/Userland/Libraries/LibWeb/CSS/CSS.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSS.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2021-2024, Sam Atkins * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace Web::CSS { @@ -33,8 +34,7 @@ bool supports(JS::VM& vm, StringView property, StringView value) } // 2. Otherwise, if property is a custom property name string, return true. - // FIXME: This check is not enough to make sure this is a valid custom property name, but it's close enough. - else if (property.starts_with("--"sv) && property.length() >= 3) { + else if (is_a_custom_property_name_string(property)) { return true; } diff --git a/Userland/Libraries/LibWeb/CSS/PropertyName.h b/Userland/Libraries/LibWeb/CSS/PropertyName.h new file mode 100644 index 00000000000..6bf7d5f8c18 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/PropertyName.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::CSS { + +// 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); +} + +}