Skip to content

Commit bafe31c

Browse files
fix(css): read a gradient as readable only with two color stops
1 parent a81b762 commit bafe31c

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎lib/css/syntax-parser.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14713,6 +14713,9 @@ const _GRADIENT_AMOUNT_RE = /^[+-]?(?:\d+\.?\d*|\.\d+)([a-z]+|%)?$/i;
1471314713
*/
1471414714
const _gradientArgumentsRead = (inner) => {
1471514715
const args = _splitTopLevelArguments(inner);
14716+
// A one-stop gradient is CSS Images 4's, which not every engine reads yet, so
14717+
// only two stops make the gradient readable everywhere.
14718+
let stops = 0;
1471614719
for (let index = 0; index < args.length; index++) {
1471714720
// A line, shape or position opens the list alone; a stop is one color
1471814721
// and its amounts. Anything else, an empty argument too, is invalid.
@@ -14759,8 +14762,9 @@ const _gradientArgumentsRead = (inner) => {
1475914762
}
1476014763
if (!color || ++colors > 1 || words !== 0) return false;
1476114764
}
14765+
if (colors !== 0) stops++;
1476214766
}
14763-
return true;
14767+
return stops > 1;
1476414768
};
1476514769

1476614770
/**

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16174,7 +16174,10 @@ describe("CssSyntax minify — a later value no engine reads keeps the one befor
1617416174
["a unit no engine reads", "linear-gradient(red 10px,blue 2foo)"],
1617516175
["a word naming no color", "linear-gradient(bogus,blue)"],
1617616176
["two keyword colors in one stop", "linear-gradient(transparent currentcolor,blue)"],
16177-
["an empty argument", "linear-gradient(red,blue,)"]
16177+
["an empty argument", "linear-gradient(red,blue,)"],
16178+
["no color stop", "linear-gradient(to right)"],
16179+
["amounts with no color", "linear-gradient(10px,20px)"],
16180+
["a single stop", "linear-gradient(to right,red)"]
1617816181
])("keeps the fallback behind %s", (_, later) => {
1617916182
const css = `${FALLBACK}background-image:${later}}`;
1618016183
expect(minifyFor(css, MODERN)).toContain("linear-gradient(red,blue)");

0 commit comments

Comments
 (0)