Skip to content

Commit 4e0733b

Browse files
committed
css-color-parser: fix normalization of hue to [0, 360] range when hue is not finite
1 parent ac70a69 commit 4e0733b

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

packages/css-color-parser/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to CSS Color Parser
22

3+
### Unreleased (patch)
4+
5+
- Fix normalization of `hue` to `[0, 360]` range when `hue` is not finite
6+
37
### 4.1.6
48

59
_June 14, 2026_

packages/css-color-parser/dist/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/css-color-parser/src/functions/hue-normalize-channel-value.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { toLowerCaseAZ } from '../util/to-lower-case-a-z';
44

55
export function normalizeHue(token: CSSToken): TokenNumber | false {
66
if (isTokenNumber(token)) {
7+
if (!Number.isNaN(token[4].value) && !Number.isFinite(token[4].value)) {
8+
token[4].value = 0;
9+
}
10+
711
token[4].value = token[4].value % 360;
812
if (token[4].value < 0) {
913
token[4].value += 360;
@@ -38,6 +42,10 @@ export function normalizeHue(token: CSSToken): TokenNumber | false {
3842
return false;
3943
}
4044

45+
if (!Number.isNaN(token[4].value) && !Number.isFinite(token[4].value)) {
46+
token[4].value = 0;
47+
}
48+
4149
value = value % 360;
4250
if (value < 0) {
4351
value += 360;

packages/css-color-parser/test/basic/basic.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ assert.deepStrictEqual(
275275
},
276276
);
277277

278+
assert.deepStrictEqual(
279+
color(parse('hsl(calc(infinity) 100% 50%)')),
280+
{
281+
colorNotation: 'hsl',
282+
channels: [0, 100, 50],
283+
alpha: 1,
284+
syntaxFlags: new Set(['has-percentage-values']),
285+
},
286+
);
287+
278288
for (const a of ['lab', 'lch', 'oklab', 'oklch', 'rgb', 'hwb', 'hsl']) {
279289
assert.deepStrictEqual(
280290
color(parse(`lab(from ${a}(none none none) l a b)`)).channels,
@@ -324,3 +334,4 @@ for (const a of ['lab', 'lch', 'oklab', 'oklch', 'rgb', 'hwb', 'hsl']) {
324334
);
325335
}
326336

337+

0 commit comments

Comments
 (0)