Skip to content

Commit 69941a6

Browse files
elas7bcoe
authored andcommitted
fix: boolean flag when next value contains the strings 'true' or 'false'.
1 parent 90b871f commit 69941a6

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function parse (args, opts) {
245245
!checkAllAliases(key, flags.counts)) {
246246
setArg(key, next)
247247
i++
248-
} else if (/true|false/.test(next)) {
248+
} else if (/^(true|false)$/.test(next)) {
249249
setArg(key, next)
250250
i++
251251
} else {

test/yargs-parser.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ describe('yargs-parser', function () {
153153
parse.should.have.property('_').and.deep.equal(['moo'])
154154
})
155155

156+
it('should not set boolean options values if the next value only contains the words "true" or "false"', function () {
157+
var parse = parser(['--verbose', 'aaatrueaaa', 'moo', '-t', 'aaafalseaaa'], {
158+
boolean: ['t', 'verbose']
159+
})
160+
parse.should.have.property('verbose', true).and.be.a('boolean')
161+
parse.should.have.property('t', true).and.be.a('boolean')
162+
parse.should.have.property('_').and.deep.equal(['aaatrueaaa', 'moo', 'aaafalseaaa'])
163+
})
164+
156165
it('should allow defining options as boolean in groups', function () {
157166
var parse = parser([ '-x', '-z', 'one', 'two', 'three' ], {
158167
boolean: ['x', 'y', 'z']

0 commit comments

Comments
 (0)