Skip to content

Commit d137227

Browse files
Mike111177bcoe
authored andcommitted
fix: Ignore multiple spaces between arguments. (#100)
1 parent 00bde7d commit d137227

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/tokenize-arg-string.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ module.exports = function (argString) {
33
if (Array.isArray(argString)) return argString
44

55
var i = 0
6+
var prevC = null
67
var c = null
78
var opening = null
89
var args = []
910

1011
for (var ii = 0; ii < argString.length; ii++) {
12+
prevC = c
1113
c = argString.charAt(ii)
1214

1315
// split on spaces unless we're in quotes.
1416
if (c === ' ' && !opening) {
15-
i++
17+
if (!(prevC === ' ')) {
18+
i++
19+
}
1620
continue
1721
}
1822

test/tokenize-arg-string.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var tokenizeArgString = require('../lib/tokenize-arg-string')
44

55
require('chai').should()
6+
var expect = require('chai').expect
67

78
describe('TokenizeArgString', function () {
89
it('handles unquoted string', function () {
@@ -37,4 +38,11 @@ describe('TokenizeArgString', function () {
3738
args[1].should.equal('hello \'world\'')
3839
args[2].should.equal('--bar=foo "bar"')
3940
})
41+
42+
it('multiple spaces only counted in quotes', function () {
43+
var args = tokenizeArgString('foo bar "foo bar"')
44+
args[0].should.equal('foo')
45+
expect(args[1]).equal('bar')
46+
expect(args[2]).equal('foo bar')
47+
})
4048
})

0 commit comments

Comments
 (0)