From 875c8137cbfc832a804be4917610bbeaafa40c7e Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Wed, 13 May 2026 15:57:53 -0300 Subject: [PATCH] test: add more test cases for pathToFileURL Signed-off-by: RafaelGSS --- test/parallel/test-url-pathtofileurl.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-url-pathtofileurl.js b/test/parallel/test-url-pathtofileurl.js index 01d27f2b736d75..5183b07226da70 100644 --- a/test/parallel/test-url-pathtofileurl.js +++ b/test/parallel/test-url-pathtofileurl.js @@ -22,11 +22,24 @@ const url = require('url'); } { - assert.throws(() => { - url.pathToFileURL('\\\\exa mple\\share\\file.txt', { windows: true }); - }, { - code: 'ERR_INVALID_URL', - }); + const forbiddenHostnameChars = [ + '\\\\exa mple\\share\\file.txt', + '\\\\host name\\share\\file.txt', // space + '\\\\host#name\\share\\file.txt', // hash + '\\\\host?name\\share\\file.txt', // question mark + '\\\\host@name\\share\\file.txt', // at sign + '\\\\host:name\\share\\file.txt', // colon + '\\\\host/name\\share\\file.txt', // forward slash + '\\\\host[name\\share\\file.txt', // left bracket + '\\\\host]name\\share\\file.txt', // right bracket + ]; + for (const path of forbiddenHostnameChars) { + assert.throws(() => { + url.pathToFileURL(path, { windows: true }); + }, { + code: 'ERR_INVALID_URL', + }, `pathToFileURL('${path}') should throw ERR_INVALID_URL`); + } } {