diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index 73f91e10..651c5c32 100644 --- a/lib/yargs-parser.ts +++ b/lib/yargs-parser.ts @@ -318,7 +318,7 @@ export class YargsParser { for (let j = 0; j < letters.length; j++) { next = arg.slice(j + 2) - if (letters[j + 1] && letters[j + 1] === '=') { + if ((letters[j + 1] && letters[j + 1] === '=') || next === '=') { value = arg.slice(j + 3) key = letters[j] diff --git a/test/yargs-parser.mjs b/test/yargs-parser.mjs index 4d94237c..87baad0d 100644 --- a/test/yargs-parser.mjs +++ b/test/yargs-parser.mjs @@ -186,6 +186,12 @@ describe('yargs-parser', function () { parse.should.have.property('_').with.length(0) }) + it('should set a short option to an empty string when a trailing equals sign supplies no value', function () { + parser(['-o='], { alias: { o: 'opt' } }).should.deep.equal({ _: [], o: '', opt: '' }) + // control: a non-empty value after the equals sign is unaffected + parser(['-o=x'], { alias: { o: 'opt' } }).should.deep.equal({ _: [], o: 'x', opt: 'x' }) + }) + it('should not set the next value as the value of a short option if that option is explicitly defined as a boolean', function () { const parse = parser(['-t', 'moo'], { boolean: 't'