tscircuit / tscircuit/schematic-trace-solver

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

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

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
13
Forks
314
Avg merge
9h 3m
Merged PRs (30d)
132

Description

getColorFromString builds its hash with acc * 31 + charCodeAt(0), which overflows to Infinity for a long enough string. hash % 360 is then NaN, so it returns an invalid color:

getColorFromString("n".repeat(300)) // -> "hsl(NaN, 100%, 50%, 1)"

A hue of NaN is not a parseable color. It should return a valid hue for any input string.

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 getColorFromString entry point and reproduce the issue with a 300-character string. Trace how the hash is calculated and verify the change with the provided example; done means every input, including very long strings, produces a valid hue rather than NaN.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
design
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.