Skip to content

fix(isHSL): allow optional whitespace after alpha separator - #2887

Open
Shuran-z wants to merge 1 commit into
validatorjs:masterfrom
Shuran-z:fix/hsl-alpha-whitespace
Open

fix(isHSL): allow optional whitespace after alpha separator#2887
Shuran-z wants to merge 1 commit into
validatorjs:masterfrom
Shuran-z:fix/hsl-alpha-whitespace

Conversation

@Shuran-z

Copy link
Copy Markdown

isHSL('hsl(120 100% 50%/0.5)') returns false, while the equivalent value with spaces around / returns true. The modern HSL expression requires a whitespace character after the alpha separator even though the separator already delimits the alpha token.

Make that whitespace optional. The existing whitespace normalization remains unchanged. Regression cases cover all four spacing combinations for hsl() and hsla(), numeric and percentage alpha values, and rejection of missing alpha values, duplicate separators, and whitespace inside numeric tokens.

Reference: CSS Color 4: HSL colors.

Validation on Windows with Node.js 24.19.0:

  • The new focused test fails on the unmodified source for hsl(120 100% 50%/0.5) and passes after the fix.
  • npm test: builds Node, ES module, and browser distributions, passes ESLint, and reports 324 passing tests.
  • Checked the compact HSL/HSLA examples and a malformed numeric token against the generated Node, browser, and minified browser entry points.
  • git diff --check passes.

Checklist

  • PR contains only related source and test changes; generated files are not committed.
  • README reviewed; this corrects the existing HSL validation contract without adding options.
  • Regression tests added.
  • Specification reference provided.

@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (a807dc7).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2887   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2599           
  Branches       658       658           
=========================================
  Hits          2599      2599           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant