Skip to content

Commit c474bc1

Browse files
authored
fix(halt-at-non-option): prevent known args from being parsed when "unknown-options-as-args" is enabled (#438)
1 parent fd30238 commit c474bc1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/yargs-parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class YargsParser {
222222
let value: string
223223

224224
// any unknown option (except for end-of-options, "--")
225-
if (arg !== '--' && isUnknownOptionAsArg(arg)) {
225+
if (arg !== '--' && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {
226226
pushPositional(arg)
227227
// ---, ---=, ----, etc,
228228
} else if (truncatedArg.match(/^---+(=|$)/)) {

test/yargs-parser.cjs

+10
Original file line numberDiff line numberDiff line change
@@ -3008,6 +3008,16 @@ describe('yargs-parser', function () {
30083008
_: ['./file.js', '--foo', '--', 'barbar']
30093009
})
30103010
})
3011+
3012+
it('is not influenced by unknown options when "unknown-options-as-args" is true', function () {
3013+
const parse = parser(
3014+
['-v', '--long', 'arg', './file.js', '--foo', '--', 'barbar'],
3015+
{ configuration: { 'halt-at-non-option': true, 'unknown-options-as-args': true }, boolean: ['foo'] }
3016+
)
3017+
parse.should.deep.equal({
3018+
_: ['-v', '--long', 'arg', './file.js', '--foo', '--', 'barbar']
3019+
})
3020+
})
30113021
})
30123022

30133023
describe('unknown-options-as-args = true', function () {

0 commit comments

Comments
 (0)