Skip to content

[Fix] Preserve empty values following short options - #87

Open
oyeong011 wants to merge 1 commit into
minimistjs:mainfrom
oyeong011:fix/short-empty-value
Open

oyeong011 wants to merge 1 commit into
minimistjs:mainfrom
oyeong011:fix/short-empty-value

Conversation

@oyeong011

Copy link
Copy Markdown

When an empty shell argument follows a short option (-s ''), minimist currently sets s: true and leaves the empty string in positional arguments. The equivalent long option already consumes the empty value.

Check whether the following argument is undefined, matching the long-option branch. The regression covers inferred and declared strings, short groups, aliases, and unchanged boolean/missing-value behavior.

Validation: failing-first regression; all 177 assertions pass with npm run tests-only; npm run lint passes (existing warnings); direct CLI invocation of this checkout returns { _: ['tail'], s: '' } for -s '' tail. Tested on Node 26.4.0; historical runtime floor and posttest network audit not exercised.

AI disclosure: OpenAI Codex assisted with investigation, implementation, tests, and this description.

Constraint: Keep the existing boolean-option semantics and Node runtime floor.
Confidence: high
Scope-risk: narrow
Tested: Failing-first regression, all 177 assertions, ESLint, and public API CLI with an empty shell argument.
AI-assistance: Implementation and tests prepared with OpenAI Codex.
@shadowspawn

Copy link
Copy Markdown
Member

This looks like a drive-by AI Pull Request. The account created 30 Pull Requests in a single day.

That said, I think the current behaviour is not as intended. But fixing it might have to be semver major, because although an uncommon case, lots of historical usage!

This is commentary, not a review.

Comment thread test/short.js
t.deepEqual(parse(['-s', '', 'tail']), { s: '', _: ['tail'] });
t.deepEqual(parse(['-s', '', 'tail'], { string: 's' }), { s: '', _: ['tail'] });
t.deepEqual(parse(['-as', '', 'tail']), { a: true, s: '', _: ['tail'] });
t.deepEqual(parse(['-s', ''], { alias: { s: 'string' } }), { s: '', string: '', _: [] });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test would be more appropriate with string long option name declared in opts.string, and s alias.

The current test is a somewhat unlikely looking edge case.

Comment thread test/short.js
t.deepEqual(parse(['-as', '', 'tail']), { a: true, s: '', _: ['tail'] });
t.deepEqual(parse(['-s', ''], { alias: { s: 'string' } }), { s: '', string: '', _: [] });
t.deepEqual(parse(['-b', ''], { boolean: 'b' }), { b: true, _: [''] });
t.deepEqual(parse(['-s']), { s: true, _: [] });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is of existing behaviour and does not look necessary.

@shadowspawn

shadowspawn commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

For reference, I think this is the relevant line mentioned for the long option (--foo) case:

next !== undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants