Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrap unknown args in quotes #2092

Merged
merged 6 commits into from Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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