Skip to content

Commit 2260367

Browse files
fix(css): keep a background position written as a length zero
The browser tier over web-platform-tests, which this branch reaches for the first time now that it sits on main, caught the slot removal taking out a position it should not: `background:0 0` became `background:none`. A length zero lands the image where an unwritten slot does, but the engine computes it as `0px` where the unwritten one computes as `0%`, so a script reading the longhand back sees the rewrite. Only a written `0%` is the initial now; a keyword still is, and `background:0 0` was a byte longer written as `background:none` anyway. Three stylesheets in the corpus said so — bootstrap.min.css and both copies of bulma.min.css, each on `background:0 0!important` in a print reset. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018tNx7sU4SbnKFhFeofDVr5
1 parent 0ee37d3 commit 2260367

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎lib/css/syntax.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11774,9 +11774,10 @@ const _positionPercentage = (written, axis) => {
1177411774
lower
1177511775
);
1177611776
if (named !== undefined) return named;
11777-
// A zero is the same place however it is spelled, and the only length that
11778-
// resolves without knowing the box.
11779-
if (_ZERO_COMPONENT_RE.test(lower) || lower === "0%") return "0%";
11777+
// Only the percentage: a length zero puts the image in the same place, but
11778+
// the engine computes it as `0px` where an unwritten slot computes as `0%`,
11779+
// so taking it out would change the value a script reads back.
11780+
if (lower === "0%") return "0%";
1178011781
return lower.endsWith("%") ? lower : null;
1178111782
};
1178211783

‎test/CssSyntax.unittest.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8852,9 +8852,11 @@ describe("CssSyntax minify — a slot holding its own initial", () => {
88528852
"a{background:0% 0% / auto repeat scroll padding-box border-box red}"
88538853
)
88548854
).toBe("a{background:red}");
8855-
// Every spelling of the place an unwritten position names.
8855+
// Every spelling of the place an unwritten position names — but not a
8856+
// length zero, which lands there and still computes as `0px` rather than
8857+
// the `0%` an unwritten slot computes as.
88568858
expect(minify("a{background:left top red}")).toBe("a{background:red}");
8857-
expect(minify("a{background:0 0 red}")).toBe("a{background:red}");
8859+
expect(minify("a{background:0 0 red}")).toBe("a{background:0 0 red}");
88588860
expect(minify("a{background:0% 0%/auto auto red}")).toBe(
88598861
"a{background:red}"
88608862
);

0 commit comments

Comments
 (0)