Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
7 changes: 7 additions & 0 deletions test/yargs-parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading