Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure empty string is added into argv._ #140

Merged
merged 2 commits into from Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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