Skip to content

Commit

Permalink
Improve error message when user passes a single array argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 30, 2021
1 parent b3e96b0 commit 20f54d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const NO_ESCAPE_REGEXP = /^[\w.-]+$/;
const DOUBLE_QUOTES_REGEXP = /"/g;

const escapeArg = arg => {
if (NO_ESCAPE_REGEXP.test(arg)) {
if (typeof arg !== 'string' || NO_ESCAPE_REGEXP.test(arg)) {
return arg;
}

Expand Down
4 changes: 4 additions & 0 deletions test/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ test(testEscapedCommand, '"foo bar"', ['foo bar']);
test(testEscapedCommand, '"\\"foo\\""', ['"foo"']);
test(testEscapedCommand, '"*"', ['*']);

test('validate against passing a single array argument', async t => {
await t.throwsAsync(execa(['echo test']), /Received an instance of Array/);
});

test('allow commands with spaces and no array arguments', async t => {
const {stdout} = await execa('command with space');
t.is(stdout, '');
Expand Down

0 comments on commit 20f54d8

Please sign in to comment.