lib: fix regular expression to detect / and \

Fixes #40305

PR-URL: https://github.com/nodejs/node/pull/40325
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
This commit is contained in:
Francesco Trotta authored and Beth Griggs committed 2021-11-23 16:28:01 +00:00
1 parent aa47c9f38f
commit 881dd7ba2a
7 files changed
+19 -5

No files matched your search

+1 -1
View File
@@ -380,7 +380,7 @@ function resolveDirectoryEntry(search) {
return resolveExtensions(new URL('index', search));
}
const encodedSepRegEx = /%2F|%2C/i;
const encodedSepRegEx = /%2F|%5C/i;
/**
* @param {URL} resolved
* @param {string | URL | undefined} base
+3
View File
@@ -2,5 +2,8 @@ import '../common/index.mjs';
import assert from 'assert';
// ./test-esm-ok.mjs
import ok from '../fixtures/es-modules/test-%65%73%6d-ok.mjs';
// ./test-esm-comma,.mjs
import comma from '../fixtures/es-modules/test-esm-comma%2c.mjs';
assert(ok);
assert(comma);
+4 -1
View File
@@ -184,10 +184,13 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
}));
}
// The use of %2F escapes in paths fails loading
// The use of %2F and %5C escapes in paths fails loading
loadFixture('pkgexports/sub/..%2F..%2Fbar.js').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));
loadFixture('pkgexports/sub/..%5C..%5Cbar.js').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));
// Package export with numeric index properties must throw a validation error
loadFixture('pkgexports-numeric').catch(mustCall((err) => {
+4 -2
View File
@@ -55,13 +55,15 @@ const { requireImport, importImport } = importer;
// Backtracking below the package base
['#subpath/sub/../../../belowbase', 'request is not a valid subpath'],
// Percent-encoded slash errors
['#external/subpath/x%2Fy', 'must not include encoded "/"'],
['#external/subpath/x%2Fy', 'must not include encoded "/" or "\\"'],
['#external/subpath/x%5Cy', 'must not include encoded "/" or "\\"'],
// Target must have a name
['#', '#'],
// Initial slash target must have a leading name
['#/initialslash', '#/initialslash'],
// Percent-encoded target paths
['#percent', 'must not include encoded "/"'],
['#encodedslash', 'must not include encoded "/" or "\\"'],
['#encodedbackslash', 'must not include encoded "/" or "\\"'],
]);
for (const [specifier, expected] of invalidImportSpecifiers) {
+4
View File
@@ -7,6 +7,10 @@ importFixture('as%2Ff').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));
importFixture('as%5Cf').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));
importFixture('as\\df').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));
+2 -1
View File
@@ -26,6 +26,7 @@
"#": "./test.js",
"#/initialslash": "./test.js",
"#notfound": "./notfound.js",
"#percent": "./..%2F/x.js"
"#encodedslash": "./..%2F/x.js",
"#encodedbackslash": "./..%5C/x.js"
}
}
+1
View File
@@ -0,0 +1 @@
export default ',';