diff --git a/index.js b/index.js index 35c02728..6e15d4e2 100644 --- a/index.js +++ b/index.js @@ -213,8 +213,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 diff --git a/test/yargs-parser.js b/test/yargs-parser.js index a482743a..6e400d3d 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -879,6 +879,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)