fix: array sub-type option respects its value, not just its presence (#415)#536
Closed
simonkundrik wants to merge 1 commit into
Closed
fix: array sub-type option respects its value, not just its presence (#415)#536simonkundrik wants to merge 1 commit into
simonkundrik wants to merge 1 commit into
Conversation
An array option configured with a falsy sub-type such as
`{ key: 'foo', number: false }` still enabled that coercion, because the
sub-type (`boolean`/`string`/`number`) was chosen by key existence
rather than by value. As a result `{ number: false }` (and
`{ number: undefined }`) coerced array values to numbers, turning
non-numeric values into NaN.
Only enable the sub-type coercion when its value is truthy.
Fixes yargs#415
Member
|
To be clear: is this Pull Request entirely AI/LLM generated? There is already a Pull Request open (#536). Is this better than the existing PR? |
Author
|
Thanks for flagging this, and sorry for the noise. I missed #533 when I opened this, it predates mine and fixes the same thing, so that one should take priority. I've closed this in its favor. And to answer your question directly: yes, this was written with AI assistance. I did review and test the change myself, but I clearly should have checked the open PRs more carefully before opening. Appreciate the heads-up. |
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 #415
An
arrayoption configured with a falsy sub-type flag still enabled that coercion. For example,{ key: 'foo', number: false }coerced the array values as numbers:Root cause
When registering array options, the sub-type (
boolean/string/number) was selected by key existence rather than by value:So
{ number: false }(orundefined) still mapped to'numbers'and turned on number coercion.Fix
Only enable the sub-type coercion when its value is truthy:
{ number: true }/{ string: true }/{ boolean: true }are unchanged; only explicit falsy values now behave as "not set".Tests
Added a regression test (
should not coerce array values as numbers when 'number' is false (#415)) using non-numeric values, since numeric-looking strings are coerced by the globalparse-numbersdefault regardless of this flag.Verified locally: full suite 363 passing (1 new),
gts lintclean.