Skip to content

Commit

Permalink
fix: convert values to strings when tokenizing (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba authored and bcoe committed Jun 7, 2019
1 parent 6055974 commit 57b7883
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/tokenize-arg-string.js
@@ -1,6 +1,8 @@
// take an un-split argv string and tokenize it.
module.exports = function (argString) {
if (Array.isArray(argString)) return argString
if (Array.isArray(argString)) {
return argString.map(e => typeof e !== 'string' ? e + '' : e)
}

argString = argString.trim()

Expand Down
6 changes: 6 additions & 0 deletions test/tokenize-arg-string.js
Expand Up @@ -12,6 +12,12 @@ describe('TokenizeArgString', function () {
args[1].should.equal('99')
})

it('handles unquoted numbers', function () {
var args = tokenizeArgString(['--foo', 9])
args[0].should.equal('--foo')
args[1].should.equal('9')
})

it('handles quoted string with no spaces', function () {
var args = tokenizeArgString("--foo 'hello'")
args[0].should.equal('--foo')
Expand Down

1 comment on commit 57b7883

@mksbrick48
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.