elgs / splitargs

Splits strings into tokens by given separator, treating quoted part as a single token.
17 stars 6 forks source link

quotes #1

Open stevenvachon opened 9 years ago

stevenvachon commented 9 years ago

On OSX, the following command line:

npm config set init.author.name Steven"Vachon" --verbose

produces the following value for process.argv:

["npm","config","set","init.author.name","Steven\"Vachon\"","--verbose"]

while splitargs produces:

["npm","config","set","init.author.name","StevenVachon","--verbose"]

What are your thoughts on how quotes should be handled?

elgs commented 9 years ago

It seems splitargs completely stripped the quotes off. I wrote some test code:

var splitargs = require('splitargs');

var i1 = "npm config set init.author.name Steven\"Vachon\" --verbose";
var o1 = splitargs(i1);
console.log(o1);

which yields the following output:

[ 'npm',
  'config',
  'set',
  'init.author.name',
  'StevenVachon',
  '--verbose' ]

@stevenvachon thanks for finding this issue. I will go ahead and improve it.

stevenvachon commented 9 years ago

Great! Thanks

elgs commented 9 years ago

@stevenvachon sorry for a long time idling, shame on me. After some consideration on this question, I think if you want to get:

["npm","config","set","init.author.name","Steven\"Vachon\"","--verbose"]

You probably need to have:

npm config set init.author.name 'Steven"Vachon"' --verbose

as input.

The reason behind this is that the primary purpose of the quotes (single or double) is to retain several space separated tokens as a single one. If quotes themselves are part of the token itself, they should be wrapped inside an enclosing quotes. Your ideas?