Skip to content

Commit 8e74080

Browse files
committed
parse: properties: utils: hsl: Support modern syntax
1 parent 7b4ca70 commit 8e74080

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/parse/properties/utils.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ static bool parse_hsl(
499499
size_t consumed = 0;
500500
css_fixed hue, sat, lit;
501501
int32_t alpha = 255;
502+
bool legacy = false;
502503
css_error error;
503504
uint8_t r = 0, g = 0, b = 0, a = 0xff;
504505

@@ -564,14 +565,18 @@ static bool parse_hsl(
564565

565566
consumeWhitespace(vector, ctx);
566567

567-
token = parserutils_vector_iterate(vector, ctx);
568-
if (!tokenIsChar(token, ','))
568+
token = parserutils_vector_peek(vector, *ctx);
569+
if (token == NULL) {
569570
return false;
571+
}
570572

573+
if (tokenIsChar(token, ',')) {
574+
parserutils_vector_iterate(vector, ctx);
575+
consumeWhitespace(vector, ctx);
576+
legacy = true;
577+
}
571578

572579
/* saturation */
573-
consumeWhitespace(vector, ctx);
574-
575580
token = parserutils_vector_iterate(vector, ctx);
576581
if ((token == NULL) || (token->type != CSS_TOKEN_PERCENTAGE))
577582
return false;
@@ -588,14 +593,16 @@ static bool parse_hsl(
588593

589594
consumeWhitespace(vector, ctx);
590595

591-
token = parserutils_vector_iterate(vector, ctx);
592-
if (!tokenIsChar(token, ','))
593-
return false;
596+
if (legacy) {
597+
token = parserutils_vector_iterate(vector, ctx);
598+
if (token == NULL || !tokenIsChar(token, ',')) {
599+
return false;
600+
}
594601

602+
consumeWhitespace(vector, ctx);
603+
}
595604

596605
/* lightness */
597-
consumeWhitespace(vector, ctx);
598-
599606
token = parserutils_vector_iterate(vector, ctx);
600607
if ((token == NULL) || (token->type != CSS_TOKEN_PERCENTAGE))
601608
return false;
@@ -614,7 +621,8 @@ static bool parse_hsl(
614621

615622
token = parserutils_vector_iterate(vector, ctx);
616623

617-
if (tokenIsChar(token, ',')) {
624+
if (( legacy && tokenIsChar(token, ',')) ||
625+
(!legacy && tokenIsChar(token, '/'))) {
618626
consumeWhitespace(vector, ctx);
619627

620628
token = parserutils_vector_iterate(vector, ctx);

0 commit comments

Comments
 (0)