Skip to content

Commit 20f54d8

Browse files
committed
Improve error message when user passes a single array argument
1 parent b3e96b0 commit 20f54d8

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/command.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const NO_ESCAPE_REGEXP = /^[\w.-]+$/;
1111
const DOUBLE_QUOTES_REGEXP = /"/g;
1212

1313
const escapeArg = arg => {
14-
if (NO_ESCAPE_REGEXP.test(arg)) {
14+
if (typeof arg !== 'string' || NO_ESCAPE_REGEXP.test(arg)) {
1515
return arg;
1616
}
1717

test/command.js

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ test(testEscapedCommand, '"foo bar"', ['foo bar']);
4141
test(testEscapedCommand, '"\\"foo\\""', ['"foo"']);
4242
test(testEscapedCommand, '"*"', ['*']);
4343

44+
test('validate against passing a single array argument', async t => {
45+
await t.throwsAsync(execa(['echo test']), /Received an instance of Array/);
46+
});
47+
4448
test('allow commands with spaces and no array arguments', async t => {
4549
const {stdout} = await execa('command with space');
4650
t.is(stdout, '');

0 commit comments

Comments
 (0)