-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Ambiguous behavior #2
Comments
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 Line 159 in 980d7ac
|
So, the correct behavior would be to treat everything as boolean flags? (even for repeat sequence) for example :
should produce:
Is it correct?
|
No, the intended parsing would be to assign the number 22 to the option Working through argument:
should produce:
|
For comparison, yargs also started from the Optimist code and does not have this issue. Here is the commit with the fix adding the anchor to match the start of the string: |
Thank you very much for the assist! |
Thanks, a PR would be most appreciated. |
Now, another discrepancy minimist
yargs-parser
Which one is correct? (I prefer minimist handling over yargs-parser tbh) |
In this case the parsing of
This is tested here: Line 8 in 980d7ac
|
And another one minimist doesn't handle correctly:
yargs-parser does handle correctly
|
Please open (For interest, I fixed a similar bug in early iteration of |
Another one, this one seems intentional Both minimist and yargs-parser:
And in general any first non-alphanumeric occurrence after alphanumeric will be treated as option value. |
And no unicode support either Both minimist and yargs-parser:
|
And another edge-case Both minimist and yargs-parser:
|
I think this is by design.
This falls under the non-alphanumeric handling of the first case, and probably as intended.
Not sure this is intentional, but the first character after the |
Consider the following case: console.log(require('minimist')(["--no-foo"], {string: ["foo"]})) Will output: { _: [], foo: false } Getting Comes from here: Lines 157 to 159 in 62fde7d
|
I think setting false when This allows the author to tell the difference between However, I don't think there is a "right" answer as the user did specify In the absence of a clear bug, I support sticking with the existing behaviour. It does not currently appear in the README or the tests. |
Another edge-case, looks like a bug: console.log(require('minimist')(['--bool', '--str', 'foobar'], {
alias:{str:['bool']}, string:["str"], boolean: true
})) Results in: { _: [ 'foobar' ], bool: [ '', '' ], str: [ '', '' ] } However, when using explicit assignment, the result is more sensible: console.log(require('minimist')(['--str=foobar', '--bool'], {
alias:{str:['bool']}, string:["str"], boolean: true
})) Results in: { _: [], str: [ 'foobar', '' ], bool: [ 'foobar', '' ] } |
I think this is likely as intended:
So Several subtle behaviours in combination! |
Yes, but there is an inconsistency between two cases. The one with explicit = assignment and the other one with positional even though they technically mean the same thing |
They don't mean the same thing when
|
Yeah, the way you frame it is correct, but the output shows that in both cases both args are not treated as booleans, both time they are treated as strings, but with inconsistent value depending on how you pass your values |
I'm comfortable with the current behaviour as being reasonable, but it will be a while before I can double-check my understanding and put a story together. With the input configuration specifying both |
What i meant by ambiguity is the inconsistent results, whenever the similar arguments are passed. |
A parser has to decide how to process The An argument with an explicit |
I'm not certain there's anything further to discuss here, so I'll close this. Please file a new issue (one per thing, please) if I'm mistaken! |
This is confusing
Case 1: as expected
Case 2: everything turned into boolean flags
Case 3: no more flags, just value again
Case 4: back to booleans
So, when it ends with a letter - its booleans, and when it ends with a number its value
Any thoughts?
The text was updated successfully, but these errors were encountered: