yargs-parser: String arguments that contain dashes do not parse properly
Eg:
foo -a 'aaa' -b 'bbb' command "-- string with dashes in it --"
This will fall afoul of this case:
https://github.com/bcoe/yargs/blob/master/lib/parser.js#L103
I ran into this trying to encrypt a private ssh key using cryptex.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 18 (5 by maintainers)
Commits related to this issue
- fix: string arguments that contain dashes do not parse properly (#145) — committed to tristanMatthias/yargs-parser by tristanMatthias 6 years ago
- Add note about option-like arguments to alter filter The Yargs parser doesn't seem to play nicely with option-like arguments that are passed as positional arguments. For more information, refer to th... — committed to mariadb-corporation/MaxScale by markus456 3 years ago
@tristanMatthias @masaeedu I’ve transferred this issue to yargs-parser, would happily accept a patch if anyone feels like take a stab at the problem 👍
@andyburke @masaeedu @tristanMatthias please try:
+ yargs-parser@12.0.0
I think it solves a bunch of issues around quotes and dashes in strings \o/
@tristanMatthias thanks for helping with the initial work, it got us going in the right direction.
The relevance of this stuff is that it’s probably going to be pretty complicated to guess at what the original string and its quote wrapping was, because every shell can parse the string into an argv differently; whatever we get in the argv should be treated as the “source of truth”. If a shell is stripping quotes before they ever make it into Node’s argv, that should be avoided by using the shell’s own rules for escaping and doubling up quotes.
@bcoe working on one now 😀
You can get around it with the bare – option, but it was non-intuitive and took me quite a bit of digging in the debugger to understand what was happening.