Skip to content
Myr

Improve process arguments validation (#873)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 2cd41ef · Browse files · 4 files+53 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+53 added−12 removed

  • tests:+41 added−8 removed
  • other:+12 added−4 removed

4 files+53 added−12 removed

modified:lib/arguments/escape.js+1 added-3 removed
modified:lib/arguments/options.js+11 added-1 removed
modified:test/arguments/options.js+34 added
131 unmodified lines
132test('execa()\'s second argument must be an array', testInvalidArgs, execa);133test('execaSync()\'s second argument must be an array', testInvalidArgs, execaSync);134test('execaNode()\'s second argument must be an array', testInvalidArgs, execaNode);135136const testInvalidArgsItems = async (t, execaMethod) => {137 t.throws(() => {138 execaMethod('echo', [{}]);139 }, {message: 'Second argument must be an array of strings: [object Object]'});140};141142test('execa()\'s second argument must not be objects', testInvalidArgsItems, execa);143test('execaSync()\'s second argument must not be objects', testInvalidArgsItems, execaSync);144test('execaNode()\'s second argument must not be objects', testInvalidArgsItems, execaNode);145146const testNullByteArg = async (t, execaMethod) => {147 t.throws(() => {148 execaMethod('echo', ['a\0b']);149 }, {message: /null bytes/});150};151152test('execa()\'s second argument must not include \\0', testNullByteArg, execa);153test('execaSync()\'s second argument must not include \\0', testNullByteArg, execaSync);154test('execaNode()\'s second argument must not include \\0', testNullByteArg, execaNode);155156const testSerializeArg = async (t, arg) => {157 const {stdout} = await execa('noop.js', [arg]);158 t.is(stdout, String(arg));159};160161test('execa()\'s arguments can be numbers', testSerializeArg, 1);162test('execa()\'s arguments can be booleans', testSerializeArg, true);163test('execa()\'s arguments can be NaN', testSerializeArg, Number.NaN);164test('execa()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY);165test('execa()\'s arguments can be null', testSerializeArg, null);166test('execa()\'s arguments can be undefined', testSerializeArg, undefined);167test('execa()\'s arguments can be bigints', testSerializeArg, 1n);168test('execa()\'s arguments can be symbols', testSerializeArg, Symbol('test'));169170const testInvalidOptions = async (t, execaMethod) => {171 t.throws(() => {172 execaMethod('echo', [], new Map());173 }, {message: /Last argument must be an options object/});
11 unmodified lines
modified:test/script.js+7 added-8 removed
236 unmodified lines
237test('$ splits expressions - \\u{0063}}', testScriptStdout, () => $`echo.js ${'a'}\u{0063}}${'b'}`, 'ac}b');238test('$ concatenates tokens - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}a\u{0063}} b`, 'c}ac}\nb');239test('$ concatenates expressions - \\u{0063}}', testScriptStdout, () => $`echo.js \u{0063}}${'a'}\u{0063}} b`, 'c}ac}\nb');240241const testScriptErrorStdout = async (t, getChildProcess, expectedStdout) => {242 const {command} = await t.throwsAsync(getChildProcess(), {code: 'ERR_INVALID_ARG_VALUE'});243 t.is(command, `echo.js ${expectedStdout}`);241const testScriptErrorStdout = async (t, getChildProcess) => {242 t.throws(getChildProcess, {message: /null bytes/});243};244246test('$ handles tokens - \\0', testScriptErrorStdout, () => $`echo.js \0`, '\0');247test('$ splits tokens - \\0', testScriptErrorStdout, () => $`echo.js a\0b`, 'a\0b');248test('$ splits expressions - \\0', testScriptErrorStdout, () => $`echo.js ${'a'}\0${'b'}`, 'a\0b');249test('$ concatenates tokens - \\0', testScriptErrorStdout, () => $`echo.js \0a\0 b`, '\0a\0 b');250test('$ concatenates expressions - \\0', testScriptErrorStdout, () => $`echo.js \0${'a'}\0 b`, '\0a\0 b');245test('$ handles tokens - \\0', testScriptErrorStdout, () => $`echo.js \0`);246test('$ splits tokens - \\0', testScriptErrorStdout, () => $`echo.js a\0b`);247test('$ splits expressions - \\0', testScriptErrorStdout, () => $`echo.js ${'a'}\0${'b'}`);248test('$ concatenates tokens - \\0', testScriptErrorStdout, () => $`echo.js \0a\0 b`);249test('$ concatenates expressions - \\0', testScriptErrorStdout, () => $`echo.js \0${'a'}\0 b`);250251const testScriptStdoutSync = (t, getChildProcess, expectedStdout) => {252 const {stdout} = getChildProcess();253 t.is(stdout, expectedStdout);
114 unmodified lines