Skip to content

[css-variables] Custom properties should *not* serialize "exactly as specified" #7329

@Loirooriol

Description

@Loirooriol

Consider this code:

var s = document.body.style;
s.setProperty("--a", "a(");
s.setProperty("--b", "b");

The spec says "Specified values of custom properties must be serialized exactly as specified by the author". That's what Blink does, but it's bad!

s.getPropertyValue("--a"); // "a("
s.getPropertyValue("--b"); // "b"
s.cssText; // "--a:a(; --b:b;"

s.cssText = s.cssText;

s.getPropertyValue("--a"); // "a(; --b:b;"
s.getPropertyValue("--b"); // ""
s.cssText; // "--a:a(; --b:b;;"

s.cssText = s.cssText;

s.getPropertyValue("--a"); // "a(; --b:b;;"
s.getPropertyValue("--b"); // ""
s.cssText; // "--a:a(; --b:b;;;"

s.cssText = s.cssText;

s.getPropertyValue("--a"); // "a(; --b:b;;;"
s.getPropertyValue("--b"); // ""
s.cssText; // "--a:a(; --b:b;;;;"

I think Firefox is better, since it round-trips:

s.getPropertyValue("--a"); // "a()"
s.getPropertyValue("--b"); // "b"
s.cssText; // "--a: a(); --b: b;"

s.cssText = s.cssText;

s.getPropertyValue("--a"); // "a()"
s.getPropertyValue("--b"); // "b"
s.cssText; // "--a: a(); --b: b;" 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions