linebender / linebender/color

Serializing Hsl colors uses a broken legacy syntax

Open Beginner friendly
#229 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
110
Forks
14
Avg merge
16h 45m
Merged PRs (30d)
1

Description

The following simple test fails:

```rust
// NOTE: Also fails with "hsl(70 8% 15%)" and "hsl(70 8 15)"
let color_str = "hsl(70, 8%, 15%)";
let color: DynamicColor = color_str.parse::>().unwrap().into();

assert_eq!(color.to_string(), color_str);
```

Actual result:

```
assertion `left == right` failed
left: "hsl(70, 8, 15)"
right: "hsl(70, 8%, 15%)"
```

The color is always serialized in the legacy format (comma delimited). But it is broken because the `%` units are required: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/hsl#syntax

> Note: `hsl()`/`hsla()` can also be written in a legacy form in which all values are separated with commas, for example `hsl(120, 75%, 25%)` or `hsla(120deg, 75%, 25%, 0.8)`. The `none` value is not permitted in the comma-separated legacy syntax, the `deg` on the hue value is optional, and the `%` units are required for the saturation and lightness values.

The `Display` impl for `DynamicColor` with `ColorSpaceTag::Hsl` calls `write_legacy_function()`, which does not add the required `%` units. It looks like using `write_modern_function()` instead would work correctly.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the DynamicColor Display implementation for ColorSpaceTag::Hsl and inspect the calls to write_legacy_function() and write_modern_function(). Run the failing Hsl parsing and formatting example, then verify that serialized saturation and lightness retain the required percent units and that the regression test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, rust
Domain
computer-graphics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.