From 57b788303e1119ba5260b273e486b73d0d638ad8 Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Fri, 7 Jun 2019 19:27:13 +0200 Subject: [PATCH] fix: convert values to strings when tokenizing (#167) --- lib/tokenize-arg-string.js | 4 +++- test/tokenize-arg-string.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenize-arg-string.js b/lib/tokenize-arg-string.js index aa19e076..fe05e27f 100644 --- a/lib/tokenize-arg-string.js +++ b/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() diff --git a/test/tokenize-arg-string.js b/test/tokenize-arg-string.js index e33c2466..6795e1d2 100644 --- a/test/tokenize-arg-string.js +++ b/test/tokenize-arg-string.js @@ -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')