Repository navigation
Conversation
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 #162
Problem
Positional args normally come back as strings, but one that follows a boolean option is turned into a number:
This happens because mri treats the arg after a boolean flag as a possible value. When the arg is not
trueorfalse, mri pushes it back to_, but it runs it through+valfirst. So03turns into3,1e3into1000and0x10into16. With vitest,vitest --run 03passes3as the filter, and that breaks string handling further down (see #162). The[123, "123", "123"]output reported in #23 has the same cause.Fix
Before calling mri,
inlineBooleanValuesrewrites a boolean option that would take the next arg as its value (e.g.--runor-rw) to the inline form (--run=true). mri then reads the next arg as an ordinary positional arg and keeps it as a string. The check follows mri's own rules: a short group's last letter takes the value,--no-*,=, and empty or dashed next args are skipped, and atrue/falsenext arg is left alone so--run falsestill setsfalse. Option values do not change.Not changed:
--run=7still adds7to the args, the same as before. That comes from the same mri branch, but it only happens when someone writes an inline value for a boolean flag.Testing
keep args after boolean options as stringstotests/index.test.ts. It fails onmain(expected [ 3, '04', 1000 ] to deeply equal [ '03', '04', '1e3' ]) and passes with this change.vitest run(22 passed),eslint .,tsgo --noEmitandprettier --check src testsall pass.parse()onmainand on this branch over 200k random argv lists, built from boolean, string and negated options, short groups,--x=v,-,true/false, empty and numeric args. Options and thrown errors matched exactly. The args differed only wheremainreturned a number and this branch returns the original string.