Skip to content

fix(color): reject signed hex digits in GetColor - #1230

Open
Kernel-Hunter wants to merge 1 commit into
gdamore:mainfrom
Kernel-Hunter:fix-getcolor-sign
Open

Kernel-Hunter wants to merge 1 commit into
gdamore:mainfrom
Kernel-Hunter:fix-getcolor-sign

Conversation

@Kernel-Hunter

@Kernel-Hunter Kernel-Hunter commented Nov 16, 2026 •

Copy link
Copy Markdown

color.GetColor parses the six hex digits with strconv.ParseInt, which accepts a leading sign. So GetColor("#-00001") returns 0xffffffff and GetColor("#+00001") returns a color with the validity bits set and the red channel at 0. Neither is a hex color, they should be Default like any other bad string.

ParseUint doesn't take a sign, so the fix is a one-word change. Test added in color/color_test.go; it fails on main and passes now, and go test ./... is green.

Summary by CodeRabbit

  • Bug Fixes
    • Color values in #RRGGBB format can now be parsed correctly when their hexadecimal value exceeds the signed 32-bit range.
    • Invalid signed hexadecimal values continue to use the default color, while valid unsigned values resolve to the expected color.

GetColor("#-00001") parsed the sign and returned a corrupted color. ParseUint rejects signs, so such strings now give Default.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

GetColor now parses hexadecimal color values as unsigned 32-bit numbers. The added tests check signed values and a valid unsigned value.

Changes: Color parsing

Layer / File(s) Summary
Hex parsing and tests
color/color.go, color/color_test.go
GetColor uses unsigned 32-bit hexadecimal parsing. Tests check that signed strings return Default and that #00000F returns NewHexColor(0xF).

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

Change: Bug fix

Merge Risk: Minimal · up to e687e

GetColor now rejects signed hex strings such as "#-00001" and returns the default color, while valid six-digit hex colors still parse. The change is small, tested, and easy to revert, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: rejecting signed hex inputs in GetColor.
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.
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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e837ac47-88f8-4fa8-b67d-d5ea7f97a483
Commits

Reviewing files that changed from the base of the PR and between 4cedad6 and e687e88.

Files selected for processing: 2

  • color/color.go
  • color/color_test.go

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

@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.02%. Comparing base (4cedad6) to head (e687e88).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1230      +/-   ##
==========================================
+ Coverage   91.94%   92.02%   +0.08%     
==========================================
  Files          49       49              
  Lines        6145     6145              
==========================================
+ Hits         5650     5655       +5     
+ Misses        478      473       -5     
  Partials       17       17              

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

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.

2 participants