Skip to content

Guard getColorFromString against NaN hue for very long strings#652

Open
abdalraof-albarbar wants to merge 1 commit into
tscircuit:mainfrom
abdalraof-albarbar:fix/color-from-string-nan
Open

Guard getColorFromString against NaN hue for very long strings#652
abdalraof-albarbar wants to merge 1 commit into
tscircuit:mainfrom
abdalraof-albarbar:fix/color-from-string-nan

Conversation

@abdalraof-albarbar

Copy link
Copy Markdown
Contributor

Closes #651

The hash accumulator overflows to Infinity for long strings, so hash % 360 came out NaN and the color was hsl(NaN, ...). This falls back to a valid hue when the hash isn't finite — every finite hash keeps the exact same output, so no existing colors change. Added a small test.

For a long enough string the `acc * 31 + charCodeAt` accumulator overflows to
Infinity, so `hash % 360` is NaN and the function returns an invalid
`hsl(NaN, 100%, 50%, 1)` color. Fall back to a valid hue when the hash isn't
finite; every finite hash keeps the exact same output.

Co-authored-by: abdalrouf-AAA <236259618+technologyet31-create@users.noreply.github.com>
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
schematic-trace-solver Ready Ready Preview, Comment Jul 9, 2026 9:56pm

Request Review

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.

getColorFromString returns hsl(NaN, ...) for very long strings

1 participant