Skip to content

fix(normalize-color): require full-string match for rgb/hsl/hwb - #58496

Open
scs0209 wants to merge 1 commit into
react:mainfrom
scs0209:fix/normalize-color-anchor-functional-forms
Open

fix(normalize-color): require full-string match for rgb/hsl/hwb#58496
scs0209 wants to merge 1 commit into
react:mainfrom
scs0209:fix/normalize-color-anchor-functional-forms

Conversation

@scs0209

@scs0209 scs0209 commented Sep 12, 2026

Copy link
Copy Markdown

Summary

@react-native/normalize-colors anchors hex color forms with ^/$, but rgb/rgba/hsl/hsla/hwb matchers did not. Because RegExp.prototype.exec finds a substring match, strings like xxrgb(1, 2, 3)yy or rgba(1,2,3,0.5)extra were accepted and normalized.

That is inconsistent with hex handling (#fff / #fff already return null) and with treating the whole input as a single color token.

Fixes #58495

Changelog

[GENERAL] [FIXED] - Reject functional color strings that only partially match rgb/hsl/hwb

Test Plan

yarn test packages/normalize-color/__tests__/normalizeColor-test.js

All 14 tests pass. Added cases for leading/trailing junk around rgb/rgba/hsl/hwb.

Minimal repro (before fix):

const normalizeColor = require('@react-native/normalize-colors');
normalizeColor('xxrgb(1, 2, 3)yy'); // was 0x010203ff, now null

Made with Cursor

Functional color regexes lacked ^/$, so junk around a valid rgb()/hsl()/hwb()
substring was accepted while hex forms already required a full match.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 12, 2026
@github-actions

Copy link
Copy Markdown

Caution

Missing Changelog

Please add a Changelog to your PR description. See Changelog format

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

normalize-color accepts functional colors with surrounding junk

1 participant