Skip to content

Commit

Permalink
fix: ensure empty string is added into argv._ (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksdrobinson authored and bcoe committed Nov 19, 2018
1 parent 1c5d556 commit 79cda98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/tokenize-arg-string.js
Expand Up @@ -25,6 +25,7 @@ module.exports = function (argString) {
// don't split the string if we're in matching
// opening or closing single and double quotes.
if (c === opening) {
if (!args[i]) args[i] = ''
opening = null
continue
} else if ((c === "'" || c === '"') && !opening) {
Expand Down
14 changes: 14 additions & 0 deletions test/tokenize-arg-string.js
Expand Up @@ -32,6 +32,20 @@ describe('TokenizeArgString', function () {
args[2].should.equal('--bar=foo bar')
})

it('handles single quoted empty string', function () {
var args = tokenizeArgString('--foo \'\' --bar=\'\'')
args[0].should.equal('--foo')
args[1].should.equal('')
args[2].should.equal('--bar=')
})

it('handles double quoted empty string', function () {
var args = tokenizeArgString('--foo "" --bar=""')
args[0].should.equal('--foo')
args[1].should.equal('')
args[2].should.equal('--bar=')
})

it('handles quoted string with embeded quotes', function () {
var args = tokenizeArgString('--foo "hello \'world\'" --bar=\'foo "bar"\'')
args[0].should.equal('--foo')
Expand Down

0 comments on commit 79cda98

Please sign in to comment.