Skip to content

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

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

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
@scs0209 scs0209 closed this by deleting the head repository Sep 17, 2026
meta-codesync Bot pushed a commit that referenced this pull request Oct 20, 2026
…59103)

Summary:
`react-native/normalize-colors` anchors its hex matchers but not `rgb`, `rgba`, `hsl`, `hsla` and `hwb`, so a string that only contains one of those calls normalizes to that color: `normalizeColor('xxrgb(1, 2, 3)yy')` is `0x010203ff` (#58495).

Animated pays for it. `AnimatedInterpolation` treats an output range that normalizes as a color as a color, so a JS-driven interpolation of a box shadow such as `inset 0 0 0 1px rgba(124, 58, 237, 1)` returns the bare `rgba(…)`, which `processBoxShadow` parses to no shadow at all.

This anchors the five functional matchers, as the hex ones already are. It is the change #58496 proposed before its author closed it.

## Changelog:

[GENERAL] [FIXED] - An Animated interpolation of a string that contains an `rgb()`, `hsl()` or `hwb()` color, such as a box shadow, interpolates the whole string instead of collapsing to the color

Pull Request resolved: #59103

Test Plan:
`normalizeColor-test.js` gains a case for strings that only contain a functional color, which returned `16909311` for `'xxrgb(1, 2, 3)yy'` before the change. `Interpolation-itest.js` gains a box-shadow range, which returned `'rgba(124, 58, 237, 1)'` before the change and now answers `'inset 0 0 0 2px rgba(124, 58, 237, 0.75)'` halfway.

- `yarn jest packages/normalize-color packages/react-native/Libraries/Animated packages/react-native/Libraries/StyleSheet`: 80 passed
- `yarn flow check`: no errors
- `eslint` and `prettier --check` on the three files: clean
- RNTester release builds on a Galaxy S23 (Android 14), [before and after](#59103 (comment)): 24 views animating an inset ring through a JS-driven interpolation draw no ring without the change and the ring at its interpolated alpha with it

Under Fantom, this PR's CI run passes `Interpolation-itest.js` and `normalizeColor-itest.js`.

Reviewed By: christophpurrer

Differential Revision: D126415662

Pulled By: javache

fbshipit-source-id: 6ea989cd8709b847ae8cf4d04d9d46d0dff9d3d4
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