Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: wrap unknown args in quotes (#2092)
  • Loading branch information
jly36963 committed Dec 28, 2021
1 parent 4ea28fb commit 6a29778
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/validation.ts
Expand Up @@ -205,7 +205,7 @@ export function validation(
'Unknown argument: %s',
'Unknown arguments: %s',
unknown.length,
unknown.join(', ')
unknown.map(s => (s.trim() ? s : `"${s}"`)).join(', ')
)
);
}
Expand Down
21 changes: 21 additions & 0 deletions test/usage.cjs
Expand Up @@ -1110,6 +1110,27 @@ describe('usage tests', () => {
r.should.have.property('exit').and.equal(true);
});

// Addresses: https://github.com/yargs/yargs/issues/2033
it('should wrap whitespace in quotes if provided as an unknown argument', () => {
const r = checkUsage(() => {
return yargs(['--opt1=hello', ' ', '--opt2=world'])
.command({
command: '$0',
desc: 'default description',
builder: yargs =>
yargs
.option('opt1', {type: 'string'})
.option('opt2', {type: 'string'}),
handler: noop,
})
.strict()
.wrap(null)
.parse();
});

r.errors.should.match(/Unknown argument: " "/);
});

it('should fail given multiple option arguments without corresponding descriptions', () => {
const r = checkUsage(() => {
const opts = {
Expand Down

0 comments on commit 6a29778

Please sign in to comment.