Skip to content

fix: handle 3-digit shorthand hex in hex_to_rgb - #5662

Merged
camdecoster merged 3 commits into
plotly:mainfrom
genrichez:fix-hex-to-rgb-shorthand
Jul 27, 2026
Merged

fix: handle 3-digit shorthand hex in hex_to_rgb#5662
camdecoster merged 3 commits into
plotly:mainfrom
genrichez:fix-hex-to-rgb-shorthand

Conversation

@genrichez

Copy link
Copy Markdown

Closes #5661.

hex_to_rgb assumed the input was always 6 digits. 3-digit shorthand like #FFF was parsed as (15, 15, 15 ) instead of (255, 255, 255).

Fix: expand 3-char codes to 6-char before slicing (e.g. FFF). Applied to both copies in _plotly_utils/colors and plotly/matplotlylib/mpltools.

Added tests for the shorthand case.

Expand 3-char hex codes (e.g. #FFF) to 6-char before parsing.
Fixes both _plotly_utils and matplotlylib copies.

Closes plotly#5661
@camdecoster camdecoster self-assigned this Jul 22, 2026
@camdecoster

Copy link
Copy Markdown
Contributor

Thanks for the PR! I'll take a look and follow up.

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Before I approve, could you please update the changelog? Also, I went ahead and combined both functions into one since they did the same thing.

@genrichez

Copy link
Copy Markdown
Author

This looks great! Before I approve, could you please update the changelog? Also, I went ahead and combined both functions into one since they did the same thing.

Thanks, Cameron!
I've added the changelog entry

@camdecoster
camdecoster merged commit e2a89c5 into plotly:main Jul 27, 2026
4 checks passed
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.

[BUG]: hex_to_rgb misparses 3-digit shorthand hex colors (#FFF -> (15,15,15))

2 participants