Skip to content

Commit

Permalink
Fix issue with numeric character in group of options
Browse files Browse the repository at this point in the history
  • Loading branch information
elas7 committed Apr 3, 2016
1 parent 48b1e6a commit d527a45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ function parse (args, opts) {
continue
}

// current letter is an alphabetic character and next value is a number
if (/[A-Za-z]/.test(letters[j]) &&
/-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
/^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
setArg(letters[j], next)
broken = true
break
Expand Down
23 changes: 23 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,29 @@ describe('yargs-parser', function () {
argv.should.have.property('n', 123)
})

it('should set n to the numeric value 123, with n at the end of a group', function () {
var argv = parser([ '-ab5n123' ])
argv.should.have.property('a', true)
argv.should.have.property('b', true)
argv.should.have.property('5', true)
argv.should.have.property('n', 123)
argv.should.have.property('_').with.length(0)
})

it('should set n to the numeric value 123, with = as separator', function () {
var argv = parser([ '-n=123' ])
argv.should.have.property('n', 123)
})

it('should set n to the numeric value 123, with n at the end of a group and = as separator', function () {
var argv = parser([ '-ab5n=123' ])
argv.should.have.property('a', true)
argv.should.have.property('b', true)
argv.should.have.property('5', true)
argv.should.have.property('n', 123)
argv.should.have.property('_').with.length(0)
})

it('should set option "1" to true, option "2" to true, and option "3" to numeric value 456', function () {
var argv = parser([ '-123', '456' ])
argv.should.have.property('1', true)
Expand Down

0 comments on commit d527a45

Please sign in to comment.