Skip to content

Commit 5e3bf84

Browse files
authored
Auto merge of #295 - servo:hwb-fix, r=emilio
color: Don't allow commas in hwb() function. It's not allowed per spec, though perhaps it should? I filed w3c/csswg-drafts#6911
2 parents f055466 + bf31c1d commit 5e3bf84

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser"
3-
version = "0.29.1"
3+
version = "0.29.2"
44
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]
55

66
description = "Rust implementation of CSS Syntax Level 3"

src/color.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ where
564564
{
565565
let (red, green, blue, uses_commas) = match_ignore_ascii_case! { name,
566566
"rgb" | "rgba" => parse_rgb_components_rgb(component_parser, arguments)?,
567-
"hsl" | "hsla" => parse_hsl_hwb(component_parser, arguments, hsl_to_rgb)?,
568-
"hwb" => parse_hsl_hwb(component_parser, arguments, hwb_to_rgb)?,
567+
"hsl" | "hsla" => parse_hsl_hwb(component_parser, arguments, hsl_to_rgb, /* allow_comma = */ true)?,
568+
"hwb" => parse_hsl_hwb(component_parser, arguments, hwb_to_rgb, /* allow_comma = */ false)?,
569569
_ => return Err(arguments.new_unexpected_token_error(Token::Ident(name.to_owned().into()))),
570570
};
571571

@@ -633,6 +633,7 @@ fn parse_hsl_hwb<'i, 't, ComponentParser>(
633633
component_parser: &ComponentParser,
634634
arguments: &mut Parser<'i, 't>,
635635
to_rgb: impl FnOnce(f32, f32, f32) -> (f32, f32, f32),
636+
allow_comma: bool,
636637
) -> Result<(u8, u8, u8, bool), ParseError<'i, ComponentParser::Error>>
637638
where
638639
ComponentParser: ColorComponentParser<'i>,
@@ -646,7 +647,7 @@ where
646647
let hue = hue_normalized_degrees / 360.;
647648

648649
// Saturation and lightness are clamped to 0% ... 100%
649-
let uses_commas = arguments.try_parse(|i| i.expect_comma()).is_ok();
650+
let uses_commas = allow_comma && arguments.try_parse(|i| i.expect_comma()).is_ok();
650651

651652
let first_percentage = component_parser.parse_percentage(arguments)?.max(0.).min(1.);
652653

src/css-parsing-tests/color4_hwb.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7774,5 +7774,6 @@
77747774
"hwb(360deg 100% 100% / 0.2)", [128, 128, 128, 51],
77757775
"hwb(360 100% 100% / 0.2)", [128, 128, 128, 51],
77767776
"hwb(360deg 100% 100% / 1)", [128, 128, 128, 255],
7777-
"hwb(360 100% 100% / 1)", [128, 128, 128, 255]
7777+
"hwb(360 100% 100% / 1)", [128, 128, 128, 255],
7778+
"hwb(360, 100%, 100%)", null
77787779
]

0 commit comments

Comments
 (0)