-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix detection of numeric value when parsing short options #3
base: main
Are you sure you want to change the base?
Fix detection of numeric value when parsing short options #3
Conversation
This change makes the short option parsing work as intended, but changes the parse results and will be a breaking change for some users. (Albeit, as is any change!) |
7564f07
to
eac091b
Compare
How likely is it that anyone will have been relying on the incorrect, and untested, results? |
eac091b
to
e2dbb25
Compare
The potentially broken use case I have in mind is a short option value that for external reasons consistently ends in a number. A user might have discovered that the value could be put straight after the short option. For example:
This might be rare since:
|
I checked what yargs does, as the most evolved optimist descendent: try-yargs $ node index.js -ABC123
{ _: [], A: true, B: true, C: 123, '$0': 'index.js' } Old minimist: try-minimist $ node index.js -ABC123
{ _: [], flag: false, A: 'BC123' } And on this branch minimist does: $ node index.js -ABC123
{ _: [], flag: false, A: true, B: true, C: 123 } |
I agree this is better/more intuitive behavior. It would, however, be quite a breaking change. |
Marking as semver-major (copied the label text and colours from qs) If this comes up a lot in issues, or if we decide never to do a major, can reconsider. |
This was reported as an issue on the original Minimist repo (comments from 2 users): Parsing multiple short option with a default value
But the behavior I was expecting was: |
And a duplicate report on original Minimist repo: Incorrectly parsed values while short param end with number
|
Problem
The parsing behaviour changes depending on whether the last character in group is a number, switching between a group of boolean options and an option taking a value. See #2 (comment)
For example:
Solution
Per #2 (comment)
There is a bug in the code detecting whether the remaining characters in the argument are a number. If the argument ends in a number it is treated as a number, even if there are letters before that.
The search
/-?\d+(\.\d*)?(e-?\d+)?$/
is not anchored at the start and thinks1b2
is a number because it ends in a number. So it treats-a1b2
like-a123
and assigns the "number" to thea
option.