Skip to content

fix: match hsb color strings case-insensitively - #309

Open
mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/uppercase-hsb-string
Open

mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/uppercase-hsb-string

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Color accepts hsb(...) / hsba(...) strings by renaming the prefix to hsv before handing them to the color parser, but the check and the replacement are case-sensitive (/hsb/). CSS color function names are case-insensitive, and the parser treats HSV(...) the same as hsv(...), so HSB(...) or HsBa(...) was not recognised and the color silently came out black instead of being parsed.

Result of the new test (I measured the first row on the original source; the second row's "before" follows from the same code path and I did not measure it separately):

input before after
new Color('HSB(120, 100%, 100%)').toHexString() #000000 (black) #00ff00
new Color('HsBa(240, 100%, 100%, 0.5)').toRgbString() not measured rgba(0,0,255,0.5)
new Color('hsb(120, 100%, 100%)') #00ff00 #00ff00

The fix makes both regular expressions case-insensitive (/hsb/i).

Tests: added should parse case-insensitive hsb and hsba strings; it fails on the original source and passes now. npm test passes (3 files, 73 tests), npm run tsc is clean and npm run lint reports 0 errors (1 warning).

Summary by CodeRabbit

  • Bug Fixes
    • 现在可以正确转换大小写混合的 HSB 和 HSBA 颜色字符串。
  • Tests
    • 补充了相关颜色解析结果的验证。

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

convertHsb2Hsv 现在会忽略字符串中 hsb 的大小写。新增测试覆盖大写 HSB 和混合大小写 HSBA 输入,以及对应的颜色结果。

Changes

HSB 字符串大小写处理

Layer / File(s) Summary
转换逻辑与解析验证
src/color.ts, tests/color.test.tsx
convertHsb2Hsv 现在以不区分大小写的方式匹配并替换 hsb。新增测试验证大写 HSB 输入解析为 #00ff00,混合大小写 HSBA 输入解析为 rgba(0,0,255,0.5)。

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: linxianxi, zombiej

Merge Risk: Minimal · up to 0f6c2

This makes uppercase and mixed-case HSB/HSBA color strings parse correctly, while lowercase behavior is unchanged. The change is small and tested, so there is no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix: match hsb color strings case-insensitively”与变更内容一致。原始样本中 hsb/hsba 前缀识别存在大小写问题,本 PR 将其改为不区分大小写的匹配,并新增测试验证大小写混合输入。标题简洁、具体,并说明了主要变更。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

兔子轻轻敲键盘,
HSB 大小写都能转换。
绿光映出十六进制,
蓝色半透明正清晰。
新测试陪着代码跑,
兔耳摇摇庆祝好。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: df0b209a-95e3-40f3-ad7a-aec4265cb233
Commits

Reviewing files that changed from the base of the PR and between cd0412a and 0f6c20a.

Files selected for processing: 2

  • src/color.ts
  • tests/color.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cd0412a) to head (0f6c20a).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #309   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           14        14           
  Lines          368       368           
  Branches        94        94           
=========================================
  Hits           368       368           

☔ 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.

@mokshupadhyay

Copy link
Copy Markdown
Contributor Author

Hi @yoyo837, a friendly ping: this is ready for review whenever you have time. Happy to adjust anything. Thanks!

This branch has not been deployed

No deployments
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