Skip to content

normalize-color accepts functional colors with surrounding junk #58495

Description

@scs0209

Description

@react-native/normalize-colors fully anchors hex matchers (^…$) but not rgb/rgba/hsl/hsla/hwb. Substring matches are therefore accepted:

normalizeColor('xxrgb(1, 2, 3)yy') // => 0x010203ff (unexpected)
normalizeColor('rgba(1,2,3,0.5)extra') // => non-null (unexpected)
normalizeColor(' #fff ') // => null (hex correctly rejects)

Steps to reproduce

  1. Open the Snack: https://snack.expo.dev/rykV9Sq-NOSJg8KWXawiP
  2. Look at rows for xxrgb(1, 2, 3)yy, rgb(1, 2, 3)yy, and rgba(1,2,3,0.5)extra
  3. Observe non-null processColor values and painted swatches (bug). Spaced hex #fff correctly stays null.

React Native Version

main / latest (package @react-native/normalize-colors, used by processColor)

Affected Platforms

  • Runtime - Android
  • Runtime - iOS
  • Runtime - Web
  • Other (please specify): pure JS @react-native/normalize-colors

Output of npx @react-native-community/cli info

N/A — reproducible via Snack / unit package without a local app install.

Stacktrace or Logs

N/A (incorrect non-null return value, no crash)

MANDATORY Reproducer

https://snack.expo.dev/rykV9Sq-NOSJg8KWXawiP

Screenshots and Videos

N/A

Fix PR: #58496

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionIssues where the author has responded to feedback.Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions