fix(model): handle boolean YAML scalars in component props and add Issue #75 tests#94
Merged
Merged
Conversation
…sue #75 tests The component property loop only checked for typeof 'number' before passing values to string-only helpers (isTokenReference, isValidColor, isParseableDimension). Boolean YAML values (e.g. visible: true) fell through to those helpers and only survived by accident due to the typeof guards added in PR #79. This change handles booleans explicitly alongside numbers so the intent is clear. Adds three tests covering the exact reproducer from Issue #75 (opacity: 0.9), boolean properties (visible: true), and a mixed case with numbers, booleans, and strings in the same component.
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
Follow-up to PR #79 (fix for Issue #75). Two changes:
1. Explicitly handle booleans in the component property loop
The component property loop in
ModelHandlerchecked fortypeof rawValue === 'number'but let booleans (visible: true,disabled: false) fall through to string-only helpers likeisTokenReferenceandisValidColor. Those functions happened to not crash because:RegExp.test()coerces its argument to a string, soisTokenReference(true)returnsfalsesilentlytypeofguards added in PR fix(cli): prevent crash on non-string YAML properties (Issue #75) #79 toparseCssColorandparseDimensionPartscatch the non-string before any.match()or.trim()callThis worked by accident, not by design. This change adds
typeof rawValue === 'boolean'next to the number check so the intent is clear and booleans never enter the string parsing path.2. Add tests for Issue #75
PR #79 fixed the crash but shipped without tests. This adds three test cases:
opacity: 0.9(the exact scenario from Issueraw.match is not a functioncrash when component property value is a non-string YAML scalar #75)visible: true(YAML parses this as a JS boolean)Testing
All 241 tests pass (including the 3 new ones).