diff --git a/servo/components/style/color/parsing.rs b/servo/components/style/color/parsing.rs index 0c8fb2dbafee..7dfec99d1ed4 100644 --- a/servo/components/style/color/parsing.rs +++ b/servo/components/style/color/parsing.rs @@ -425,9 +425,13 @@ fn parse_color_with_color_space<'i, 't>( let color_space = PredefinedColorSpace::parse(arguments)?; let component_parser = ComponentParser { context: component_parser.context, - origin_color: component_parser - .origin_color - .map(|c| c.to_color_space(ColorSpace::from(color_space))), + origin_color: component_parser.origin_color.map(|c| { + // If the origin color was in legacy srgb, converting it won't + // change it to modern syntax. So make sure it's in modern syntax. + let mut c = c.to_color_space(ColorSpace::from(color_space)); + c.flags.remove(ColorFlags::IS_LEGACY_SRGB); + c + }), }; let c1 = component_parser.parse_number_or_percentage(arguments, true)?; diff --git a/testing/web-platform/tests/css/css-color/parsing/color-valid-relative-color.html b/testing/web-platform/tests/css/css-color/parsing/color-valid-relative-color.html index aaecb5689d8b..7b44b4f0bfcd 100644 --- a/testing/web-platform/tests/css/css-color/parsing/color-valid-relative-color.html +++ b/testing/web-platform/tests/css/css-color/parsing/color-valid-relative-color.html @@ -763,6 +763,10 @@ fuzzy_test_valid_color(`lch(from var(--mycolor) l 0 h)`); fuzzy_test_valid_color(`var(--mygray)`); fuzzy_test_valid_color(`lch(from var(--mygray) l 30 h)`); + + // Ensure that converting between legacy and modern sRGB color spaces work as expected. + fuzzy_test_valid_color(`color(from rebeccapurple srgb r g b)`, `color(srgb 0.4 0.2 0.6)`, 0.01); + fuzzy_test_valid_color(`rgb(from color(srgb 0.4 0.2 0.6) r g b)`, `color(srgb 0.4 0.2 0.6)`, 0.01);