Skip to content

Fix text-shadow parsing: negative/decimal lengths and color ordering#507

Open
durvesh1992 wants to merge 2 commits into
react:mainfrom
durvesh1992:fix-text-shadow-negative-decimal-length
Open

Fix text-shadow parsing: negative/decimal lengths and color ordering#507
durvesh1992 wants to merge 2 commits into
react:mainfrom
durvesh1992:fix-text-shadow-negative-decimal-length

Conversation

@durvesh1992

@durvesh1992 durvesh1992 commented Jun 29, 2026

Copy link
Copy Markdown

Summary

Fixes a few related correctness bugs in parseTextShadow (native), all stemming from how the parser distinguishes a length token from the color token.

1. Negative and decimal lengths

LENGTH_REG only matched non-negative integer lengths (e.g. 3px). When the last token was a negative offset or a decimal blur radius with no explicit color, it was misclassified as the color — dropping the offset/blur and producing a bogus color value:

  • text-shadow: 1px -2px → vertical offset dropped, textShadowColor set to "-2px"
  • text-shadow: 1px 1px 2.5px → blur dropped, textShadowColor set to "2.5px"

Fixed by allowing an optional leading minus sign and decimals in LENGTH_REG, matching the pattern already used by CSSLengthUnitValue.

2. Color specified before the offsets

CSS allows the color to appear either before or after the offset values, but parseValue only inspected the last token. A leading color was misparsed:

  • text-shadow: red 1px 2px 3px → color dropped, offsetX became "red"

Fixed by detecting the color as the single non-length token regardless of position.

Test plan

Added unit tests covering negative offsets, decimal blur radii, and color-before/after ordering (failing before, passing after). Full jest suite passes (901 tests), flow check reports no errors, and eslint is clean.

The length regex used to detect whether the final token of a text-shadow
is a length or a color only matched non-negative integer lengths (e.g.
"3px"). As a result, a trailing negative offset ("1px -2px") or a
trailing decimal blur radius ("1px 1px 2.5px") was misclassified as the
color, dropping the offset/blur and producing a bogus color value.

Allow an optional leading minus sign and decimal values in the length
regex, matching the pattern already used by CSSLengthUnitValue.

Add unit tests covering negative offsets and decimal blur radii with and
without an explicit color.
@meta-cla meta-cla Bot added the cla signed label Jun 29, 2026
CSS allows the text-shadow color to appear either before or after the
offset values. parseValue only inspected the last token, so a leading
color (e.g. "red 1px 1px") was misparsed: the color was dropped and the
first offset became the color string.

Detect the color as the single non-length token regardless of position.
@durvesh1992 durvesh1992 changed the title Fix textShadow parsing of negative and decimal length values Fix text-shadow parsing: negative/decimal lengths and color ordering Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant