Skip to content

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

Description

@abdalraof-albarbar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions