Skip to content
Permalink
Browse files
CSSStyleValue.parse() should throw when passed an empty string as cus…
…tom property value

https://bugs.webkit.org/show_bug.cgi?id=247026

Reviewed by Geoffrey Garen.

CSSStyleValue.parse() / CSSStyleValue.parseAll() should throw when passed an
empty string as custom property value.

This matches Blink's behavior and this behavior is covered by WPT tests.

* LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-objects/parse-invalid-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-objects/parseAll-invalid-expected.txt:
* Source/WebCore/css/typedom/CSSStyleValueFactory.cpp:
(WebCore::CSSStyleValueFactory::extractCustomCSSValues):

Canonical link: https://commits.webkit.org/256011@main
  • Loading branch information
cdumez committed Oct 26, 2022
1 parent 9cbd8da commit 98e13fd6a1c257a63bb5be5ddf8b9be9d87f602f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
@@ -3,5 +3,5 @@ PASS CSSStyleValue.parse() with empty property name throws TypeError
PASS CSSStyleValue.parse() with unsupported property name throws TypeError
PASS CSSStyleValue.parse() with invalid value for valid property throws TypeError
PASS CSSStyleValue.parse() with invalid value for shorthand property throws TypeError
FAIL CSSStyleValue.parse() with invalid value for custom property throws TypeError assert_throws_js: function "() => CSSStyleValue.parse('--foo', '')" did not throw
PASS CSSStyleValue.parse() with invalid value for custom property throws TypeError

@@ -3,5 +3,5 @@ PASS CSSStyleValue.parseAll() with empty property name throws TypeError
PASS CSSStyleValue.parseAll() with unsupported property name throws TypeError
PASS CSSStyleValue.parseAll() with invalid value for valid property throws TypeError
PASS CSSStyleValue.parseAll() with invalid value for shorthand property throws TypeError
FAIL CSSStyleValue.parseAll() with invalid value for custom property throws TypeError assert_throws_js: function "() => CSSStyleValue.parseAll('--foo', '')" did not throw
PASS CSSStyleValue.parseAll() with invalid value for custom property throws TypeError

@@ -91,6 +91,9 @@ ExceptionOr<void> CSSStyleValueFactory::extractShorthandCSSValues(Vector<Ref<CSS

ExceptionOr<void> CSSStyleValueFactory::extractCustomCSSValues(Vector<Ref<CSSValue>>& cssValues, const AtomString& customPropertyName, const String& cssText)
{
if (cssText.isEmpty())
return Exception { TypeError, "Value cannot be parsed"_s };

auto styleDeclaration = MutableStyleProperties::create();

constexpr bool important = true;

0 comments on commit 98e13fd

Please sign in to comment.