diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-06-11 12:41:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 11:41:44 +0000 |
commit | 6a356aff1380e79d67738c5b43aa2b5fee76600d (patch) | |
tree | be4aadc62a523ff280820958a1a3829f1a18ca7d /tests/node_compat/test/parallel/test-url-pathtofileurl.js | |
parent | 3d41b486da7dcba49c8a18b45425e356c329d986 (diff) |
chore: sync up Node.js test files for v20.11.1 (#24066)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
Diffstat (limited to 'tests/node_compat/test/parallel/test-url-pathtofileurl.js')
-rw-r--r-- | tests/node_compat/test/parallel/test-url-pathtofileurl.js | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/tests/node_compat/test/parallel/test-url-pathtofileurl.js b/tests/node_compat/test/parallel/test-url-pathtofileurl.js index 5bbabc225..d0f2f4b97 100644 --- a/tests/node_compat/test/parallel/test-url-pathtofileurl.js +++ b/tests/node_compat/test/parallel/test-url-pathtofileurl.js @@ -36,13 +36,30 @@ const url = require('url'); // Missing server: assert.throws(() => url.pathToFileURL('\\\\\\no-server'), { - code: 'ERR_INVALID_ARG_VALUE' + code: 'ERR_INVALID_ARG_VALUE', }); // Missing share or resource: assert.throws(() => url.pathToFileURL('\\\\host'), { - code: 'ERR_INVALID_ARG_VALUE' + code: 'ERR_INVALID_ARG_VALUE', }); + + // Regression test for direct String.prototype.startsWith call + assert.throws(() => url.pathToFileURL([ + '\\\\', + { [Symbol.toPrimitive]: () => 'blep\\blop' }, + ]), { + code: 'ERR_INVALID_ARG_TYPE', + }); + assert.throws(() => url.pathToFileURL(['\\\\', 'blep\\blop']), { + code: 'ERR_INVALID_ARG_TYPE', + }); + assert.throws(() => url.pathToFileURL({ + [Symbol.toPrimitive]: () => '\\\\blep\\blop', + }), { + code: 'ERR_INVALID_ARG_TYPE', + }); + } else { // UNC paths on posix are considered a single path that has backslashes: const fileURL = url.pathToFileURL('\\\\nas\\share\\path.txt').href; @@ -151,3 +168,19 @@ const url = require('url'); assert.strictEqual(actual, expected); } } + +// Test for non-string parameter +{ + for (const badPath of [ + undefined, null, true, 42, 42n, Symbol('42'), NaN, {}, [], () => {}, + Promise.resolve('foo'), + new Date(), + new String('notPrimitive'), + { toString() { return 'amObject'; } }, + { [Symbol.toPrimitive]: (hint) => 'amObject' }, + ]) { + assert.throws(() => url.pathToFileURL(badPath), { + code: 'ERR_INVALID_ARG_TYPE', + }); + } +} |