Fix length validators wrongly accepting comma-prefixed values#1741
Open
durvesh1992 wants to merge 1 commit into
Open
Fix length validators wrongly accepting comma-prefixed values#1741durvesh1992 wants to merge 1 commit into
durvesh1992 wants to merge 1 commit into
Conversation
isAbsoluteLength and isRelativeLength built their regex with the character class [-,+], which includes a literal comma. As a result the `valid-styles` ESLint rule accepted malformed lengths such as ',4px' and ',4rem'. Change [-,+] to [+-] in both validators so only an optional leading sign is allowed. Legitimate values (4px, -4px, +4px, 4rem, ...) still validate. This is the same defect fixed for the percentage validator in facebook#1574, which did not touch the two length files. Added regression tests (textUnderlineOffset is length-only) that fail before the change and pass after; full eslint-plugin suite is green.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The ESLint
valid-stylesrule accepts malformed CSS lengths like',4px'and',4rem'. Both length validators build their regex with the character class[-,+], which includes a literal comma:So a leading comma is accepted as if it were a sign. This changes
[-,+]to[+-]in bothisAbsoluteLength.jsandisRelativeLength.js, allowing only an optional leading sign. Legitimate values (4px,-4px,+4px,4rem, …) are unaffected.This is the same defect fixed for the percentage validator in #1574, which did not touch the two length files — so this complements that PR rather than overlapping it.
Test plan
Added regression tests in
stylex-valid-styles-test.jsusingtextUnderlineOffset(a length-only property, so the length validators are exercised directly rather than thenon-numeric stringfallback that properties likeheightallow).',4px'/',4rem'cases raise 0 errors (bug) → tests fail.@stylexjs/eslint-pluginsuite: 549 passed, 9 suites, no regressions.