fix(model): handle numeric component prop values without crashing#43
Open
tejas100 wants to merge 1 commit intogoogle-labs-code:mainfrom
Open
fix(model): handle numeric component prop values without crashing#43tejas100 wants to merge 1 commit intogoogle-labs-code:mainfrom
tejas100 wants to merge 1 commit intogoogle-labs-code:mainfrom
Conversation
Numeric values such as fontWeight: 600 or borderWidth: 1 are valid per the DESIGN.md spec, which states bare numbers and quoted strings are equivalent. However, the component property loop in ModelHandler passed all rawValues directly to isTokenReference / isValidColor, both of which call .match() and crash when rawValue is a number. Fix: add a typeof rawValue === 'number' guard at the top of the loop, storing numeric values as-is — matching the pattern already used by parseTypography for the same property. Fixes google-labs-code#42
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.
Fixes #42
Problem
The
lintcommand crashes withUnexpected error during model building: raw.match is not a functionwhen a component defines a numeric prop likefontWeight: 600orborderWidth: 1. The spec explicitly states barenumbers and quoted strings are equivalent, so this is a spec violation.
Root Cause
In Phase 3 of
ModelHandler, all component prop values were passeddirectly to
isTokenReference()andisValidColor(), both of which call.match()internally. WhenrawValueis a number,.matchdoesn't exist— crash.
Fix
Added a
typeof rawValue === 'number'guard at the top of the componentproperty loop, storing numeric values as-is. This mirrors the pattern
already used by
parseTypographyfor the same property.Tests
Added 4 new test cases covering:
fontWeight: 600(exact repro from issue)fontWeight: 700stored correctly as a numberborderWidth: 1(also mentioned in issue)