From c14ff69d6968b7ac644cb47b039005d54344d576 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Tue, 18 Jul 2023 23:24:44 +0800 Subject: [PATCH] fs: mention `URL` in NUL character error message PR-URL: https://github.com/nodejs/node/pull/48828 Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Antoine du Hamel --- lib/internal/fs/utils.js | 2 +- .../test-child-process-reject-null-bytes.js | 102 +++++++++--------- test/parallel/test-fs-whatwg-url.js | 9 -- 3 files changed, 52 insertions(+), 61 deletions(-) diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 48f9671c8cf677..6e6c7ee58cf5d1 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -376,7 +376,7 @@ const nullCheck = hideStackFrames((path, propName, throwError = true) => { const err = new ERR_INVALID_ARG_VALUE( propName, path, - 'must be a string or Uint8Array without null bytes', + 'must be a string, Uint8Array, or URL without null bytes', ); if (throwError) { throw err; diff --git a/test/parallel/test-child-process-reject-null-bytes.js b/test/parallel/test-child-process-reject-null-bytes.js index 7d84534f80c75f..b5239cdddcdd07 100644 --- a/test/parallel/test-child-process-reject-null-bytes.js +++ b/test/parallel/test-child-process-reject-null-bytes.js @@ -18,56 +18,56 @@ const { throws(() => exec(`${process.execPath} ${__filename} AAA BBB\0XXX CCC`, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'command' must be a string without null bytes/ + name: 'TypeError', }); throws(() => exec('BBB\0XXX AAA CCC', mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'command' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execSync(`${process.execPath} ${__filename} AAA BBB\0XXX CCC`), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'command' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execSync('BBB\0XXX AAA CCC'), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'command' must be a string without null bytes/ + name: 'TypeError', }); // Tests for the 'file' argument throws(() => spawn('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'file' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFile('BBB\0XXX', mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'file' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFileSync('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'file' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawn('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'file' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawnSync('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'file' must be a string without null bytes/ + name: 'TypeError', }); // Tests for the 'modulePath' argument throws(() => fork('BBB\0XXX'), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'modulePath' must be a string or Uint8Array without null bytes/ + name: 'TypeError', }); // Tests for the 'args' argument @@ -77,123 +77,123 @@ throws(() => fork('BBB\0XXX'), { throws(() => execFile(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC'], mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'args\[2\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFileSync(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'args\[2\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => fork(__filename, ['AAA', 'BBB\0XXX', 'CCC']), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'args\[2\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawn(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'args\[2\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawnSync(process.execPath, [__filename, 'AAA', 'BBB\0XXX', 'CCC']), { code: 'ERR_INVALID_ARG_VALUE', - message: /The argument 'args\[2\]' must be a string without null bytes/ + name: 'TypeError', }); // Tests for the 'options.cwd' argument throws(() => exec(process.execPath, { cwd: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/ + name: 'TypeError', }); throws(() => execFile(process.execPath, { cwd: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/ + name: 'TypeError', }); throws(() => execFileSync(process.execPath, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/ + name: 'TypeError', }); throws(() => execSync(process.execPath, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/ + name: 'TypeError', }); throws(() => fork(__filename, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/ + name: 'TypeError', }); throws(() => spawn(process.execPath, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/ + name: 'TypeError', }); throws(() => spawnSync(process.execPath, { cwd: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.cwd' must be a string or Uint8Array without null bytes/ + name: 'TypeError', }); // Tests for the 'options.argv0' argument throws(() => exec(process.execPath, { argv0: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.argv0' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFile(process.execPath, { argv0: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.argv0' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFileSync(process.execPath, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.argv0' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execSync(process.execPath, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.argv0' must be a string without null bytes/ + name: 'TypeError', }); throws(() => fork(__filename, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.argv0' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawn(process.execPath, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.argv0' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawnSync(process.execPath, { argv0: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.argv0' must be a string without null bytes/ + name: 'TypeError', }); // Tests for the 'options.shell' argument throws(() => exec(process.execPath, { shell: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.shell' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFile(process.execPath, { shell: 'BBB\0XXX' }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.shell' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFileSync(process.execPath, { shell: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.shell' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execSync(process.execPath, { shell: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.shell' must be a string without null bytes/ + name: 'TypeError', }); // Not testing fork() because it doesn't accept the shell option (internally it @@ -201,94 +201,94 @@ throws(() => execSync(process.execPath, { shell: 'BBB\0XXX' }), { throws(() => spawn(process.execPath, { shell: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.shell' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawnSync(process.execPath, { shell: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.shell' must be a string without null bytes/ + name: 'TypeError', }); // Tests for the 'options.env' argument throws(() => exec(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => exec(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFile(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFile(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }, mustNotCall()), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFileSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execFileSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => execSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => fork(__filename, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => fork(__filename, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawn(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawn(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawnSync(process.execPath, { env: { 'AAA': 'BBB\0XXX' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['AAA'\]' must be a string without null bytes/ + name: 'TypeError', }); throws(() => spawnSync(process.execPath, { env: { 'BBB\0XXX': 'AAA' } }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.env\['BBB\0XXX'\]' must be a string without null bytes/ + name: 'TypeError', }); // Tests for the 'options.execPath' argument throws(() => fork(__filename, { execPath: 'BBB\0XXX' }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.execPath' must be a string without null bytes/ + name: 'TypeError', }); // Tests for the 'options.execArgv' argument throws(() => fork(__filename, { execArgv: ['AAA', 'BBB\0XXX', 'CCC'] }), { code: 'ERR_INVALID_ARG_VALUE', - message: /The property 'options\.execArgv\[1\]' must be a string without null bytes/ + name: 'TypeError', }); diff --git a/test/parallel/test-fs-whatwg-url.js b/test/parallel/test-fs-whatwg-url.js index 829cfa92fafebd..7c99999a68dfad 100644 --- a/test/parallel/test-fs-whatwg-url.js +++ b/test/parallel/test-fs-whatwg-url.js @@ -5,7 +5,6 @@ const fixtures = require('../common/fixtures'); const assert = require('assert'); const path = require('path'); const fs = require('fs'); -const os = require('os'); function pathToFileURL(p) { if (!path.isAbsolute(p)) @@ -35,7 +34,6 @@ assert.throws( { code: 'ERR_INVALID_URL_SCHEME', name: 'TypeError', - message: 'The URL must be of scheme file' }); // pct-encoded characters in the path will be decoded and checked @@ -49,7 +47,6 @@ if (common.isWindows) { { code: 'ERR_INVALID_FILE_URL_PATH', name: 'TypeError', - message: 'File URL path must not include encoded \\ or / characters' } ); }); @@ -60,8 +57,6 @@ if (common.isWindows) { { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', - message: 'The argument \'path\' must be a string or Uint8Array without ' + - "null bytes. Received 'c:\\\\tmp\\\\\\x00test'" } ); } else { @@ -74,7 +69,6 @@ if (common.isWindows) { { code: 'ERR_INVALID_FILE_URL_PATH', name: 'TypeError', - message: 'File URL path must not include encoded / characters' }); }); assert.throws( @@ -84,7 +78,6 @@ if (common.isWindows) { { code: 'ERR_INVALID_FILE_URL_HOST', name: 'TypeError', - message: `File URL host must be "localhost" or empty on ${os.platform()}` } ); assert.throws( @@ -94,8 +87,6 @@ if (common.isWindows) { { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError', - message: "The argument 'path' must be a string or Uint8Array without " + - "null bytes. Received '/tmp/\\x00test'" } ); }