Fix two correctness bugs in style-value-parser (shorthand hex + border-radius)#1742
Open
durvesh1992 wants to merge 2 commits into
Open
Fix two correctness bugs in style-value-parser (shorthand hex + border-radius)#1742durvesh1992 wants to merge 2 commits into
durvesh1992 wants to merge 2 commits into
Conversation
The HashColor parser accepts 3-, 6-, and 8-digit hex, but the r/g/b/a getters sliced fixed 2-char windows, assuming 6/8 digits. For shorthand like '#f0a' (= #ff00aa) this returned r=240, g=10, b=NaN instead of 255/0/170. Add a private #expanded() helper that doubles each digit of a 3-digit value before slicing; 6/8-digit values are unchanged. The stored value is left untouched so toString() and equality semantics are preserved. Adds a regression test that fails before the change and passes after.
BorderRadiusShorthand.toString() initialized the vertical group string (sStr) from the horizontal corner values instead of the vertical ones — a copy-paste of the horizontal initializer. The following branches only overwrite sStr when the vertical radii are symmetric, so a fully asymmetric vertical group (e.g. 1px 2px 3px 4px) fell through to the wrong horizontal-based default, emitting '5px / 5px 5px 5px 5px' instead of '5px / 1px 2px 3px 4px'. Initialize sStr from the vertical values. Adds a toString() regression test (the shorthand toString path previously had no coverage).
|
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.
Two small, independent correctness fixes in
@stylexjs/style-value-parser, each with a regression test. Both were found by reading the code; the affected APIs currently have little/no test coverage on these paths.1.
HashColorchannel getters mishandle 3-digit shorthand hexHashColor.parseraccepts 3-, 6-, and 8-digit hex, but ther/g/b/agetters slice fixed 2-char windows assuming 6/8 digits. For shorthand like#f0a(=#ff00aa→ 255/0/170) they returnedr=240, g=10, b=NaN.Fix: a private
#expanded()helper doubles each digit of a 3-digit value before slicing; 6/8-digit values are untouched, and the storedvalueis left intact sotoString()/equality semantics are unchanged.2.
border-radiusserializer drops asymmetric vertical radiiBorderRadiusShorthand.toString()initialized the vertical group string (sStr) from the horizontal corner values — a copy-paste of the horizontal initializer. The following branches only overwritesStrwhen the vertical radii are symmetric, so a fully asymmetric vertical group fell through to the wrong default:Fix: initialize
sStrfrom the vertical values (one line).Test plan
Added regression tests in
color-test.jsandborder-radius.test.js(both fail before the respective fix, pass after). Full package suite green: