Skip to content

Commit cddcf31

Browse files
committed
parse: properties: utils: hsl: Support modern syntax
1 parent bc814d4 commit cddcf31

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

@@ -563,14 +564,18 @@ static bool parse_hsl(
563564

564565
consumeWhitespace(vector, ctx);
565566

566-
token = parserutils_vector_iterate(vector, ctx);
567-
if (!tokenIsChar(token, ','))
567+
token = parserutils_vector_peek(vector, *ctx);
568+
if (token == NULL) {
568569
return false;
570+
}
569571

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

571578
/* saturation */
572-
consumeWhitespace(vector, ctx);
573-
574579
token = parserutils_vector_iterate(vector, ctx);
575580
if ((token == NULL) || (token->type != CSS_TOKEN_PERCENTAGE))
576581
return false;
@@ -587,14 +592,16 @@ static bool parse_hsl(
587592

588593
consumeWhitespace(vector, ctx);
589594

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

601+
consumeWhitespace(vector, ctx);
602+
}
594603

595604
/* lightness */
596-
consumeWhitespace(vector, ctx);
597-
598605
token = parserutils_vector_iterate(vector, ctx);
599606
if ((token == NULL) || (token->type != CSS_TOKEN_PERCENTAGE))
600607
return false;
@@ -613,7 +620,8 @@ static bool parse_hsl(
613620

614621
token = parserutils_vector_iterate(vector, ctx);
615622

616-
if (tokenIsChar(token, ',')) {
623+
if (( legacy && tokenIsChar(token, ',')) ||
624+
(!legacy && tokenIsChar(token, '/'))) {
617625
consumeWhitespace(vector, ctx);
618626

619627
token = parserutils_vector_iterate(vector, ctx);

0 commit comments

Comments
 (0)