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

Most upvoted comments

@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.