Skip to content

Commit 79cda98

Browse files
jacksdrobinsonbcoe
authored andcommitted
fix: ensure empty string is added into argv._ (#140)
1 parent 1c5d556 commit 79cda98

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/tokenize-arg-string.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = function (argString) {
2525
// don't split the string if we're in matching
2626
// opening or closing single and double quotes.
2727
if (c === opening) {
28+
if (!args[i]) args[i] = ''
2829
opening = null
2930
continue
3031
} else if ((c === "'" || c === '"') && !opening) {

test/tokenize-arg-string.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ describe('TokenizeArgString', function () {
3232
args[2].should.equal('--bar=foo bar')
3333
})
3434

35+
it('handles single quoted empty string', function () {
36+
var args = tokenizeArgString('--foo \'\' --bar=\'\'')
37+
args[0].should.equal('--foo')
38+
args[1].should.equal('')
39+
args[2].should.equal('--bar=')
40+
})
41+
42+
it('handles double quoted empty string', function () {
43+
var args = tokenizeArgString('--foo "" --bar=""')
44+
args[0].should.equal('--foo')
45+
args[1].should.equal('')
46+
args[2].should.equal('--bar=')
47+
})
48+
3549
it('handles quoted string with embeded quotes', function () {
3650
var args = tokenizeArgString('--foo "hello \'world\'" --bar=\'foo "bar"\'')
3751
args[0].should.equal('--foo')

0 commit comments

Comments
 (0)