Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: d140987bf3e107e7bda5dca4eca9082b7569f289
https://github.com/WebKit/WebKit/commit/d140987bf3e107e7bda5dca4eca9082b7569f289
Author: Ahmad Saleem <[email protected]>
Date: 2026-08-20 (Thu, 20 Aug 2026)
Changed paths:
A
LayoutTests/imported/w3c/web-platform-tests/css/cssom/serialize-variable-reference-whitespace-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/css/cssom/serialize-variable-reference-whitespace.html
M Source/WebCore/css/parser/CSSPropertyParser.cpp
Log Message:
-----------
Trailing whitespace is not trimmed when setting a value containing var()
through the CSSOM
https://bugs.webkit.org/show_bug.cgi?id=320186
rdar://183735232
Reviewed by Sam Weinig and Antti Koivisto.
Setting a property to a value that contains an arbitrary substitution function
(var(), env(), attr(), ...) through the CSSOM kept any trailing whitespace in
the serialized value:
element.style.color = ' var(--a) ';
element.style.color; // "var(--a) " instead of "var(--a)"
Such a value cannot be parsed into a CSSValue, so it is stored as the original
token sequence in a CSSSubstitutionValue and serialized back from those tokens.
CSSPropertyParser::parseValue only consumed leading whitespace, so the trailing
whitespace tokens ended up in the sequence and in its serialization. Values
that do parse (e.g. "red ") were unaffected, as was any value coming from
a style attribute or a style sheet, since CSSParser::consumeDeclaration trims
trailing whitespace per the "consume a declaration" algorithm, and so does the
CSSOM path for custom properties in CSSParser::parseCustomPropertyValue.
Trim trailing whitespace in CSSPropertyParser::parseValue as well, which covers
both the longhand and the shorthand case. Firefox and Chrome both trim here.
Test:
imported/w3c/web-platform-tests/css/cssom/serialize-variable-reference-whitespace.html
*
LayoutTests/imported/w3c/web-platform-tests/css/cssom/serialize-variable-reference-whitespace-expected.txt:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/css/cssom/serialize-variable-reference-whitespace.html:
Added.
* Source/WebCore/css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::parseValue):
Canonical link: https://commits.webkit.org/319554@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications