diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index 48a2d0f2..296b2cb0 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 4c692375..4cab6957 100644 --- a/test/yargs-parser.mjs +++ b/test/yargs-parser.mjs @@ -186,6 +186,13 @@ describe('yargs-parser', function () { parse.should.have.property('_').with.length(0) }) + // Addresses: https://github.com/yargs/yargs-parser/issues/367 + 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'