Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 243b2fb

Browse filesBrowse files
fasttimerichardlau
authored andcommitted
lib: fix regular expression to detect / and \
PR-URL: #40325 Backport-PR-URL: #40565 Fixes: #40305 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>
1 parent 02b432a commit 243b2fb
Copy full SHA for 243b2fb

7 files changed

+19-5Lines changed: 19 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/modules/esm/resolve.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/resolve.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function resolveDirectoryEntry(search) {
254254
return resolveExtensions(new URL('index', search));
255255
}
256256

257-
const encodedSepRegEx = /%2F|%2C/i;
257+
const encodedSepRegEx = /%2F|%5C/i;
258258
function finalizeResolution(resolved, base) {
259259
if (RegExpPrototypeTest(encodedSepRegEx, resolved.pathname))
260260
throw new ERR_INVALID_MODULE_SPECIFIER(
Collapse file

‎test/es-module/test-esm-encoded-path.mjs‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-encoded-path.mjs
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ import '../common/index.mjs';
22
import assert from 'assert';
33
// ./test-esm-ok.mjs
44
import ok from '../fixtures/es-modules/test-%65%73%6d-ok.mjs';
5+
// ./test-esm-comma,.mjs
6+
import comma from '../fixtures/es-modules/test-esm-comma%2c.mjs';
57

68
assert(ok);
9+
assert(comma);
Collapse file

‎test/es-module/test-esm-exports.mjs‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-exports.mjs
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,13 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
162162
}));
163163
}
164164

165-
// The use of %2F escapes in paths fails loading
165+
// The use of %2F and %5C escapes in paths fails loading
166166
loadFixture('pkgexports/sub/..%2F..%2Fbar.js').catch(mustCall((err) => {
167167
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
168168
}));
169+
loadFixture('pkgexports/sub/..%5C..%5Cbar.js').catch(mustCall((err) => {
170+
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
171+
}));
169172

170173
// Package export with numeric index properties must throw a validation error
171174
loadFixture('pkgexports-numeric').catch(mustCall((err) => {
Collapse file

‎test/es-module/test-esm-imports.mjs‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-imports.mjs
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ const { requireImport, importImport } = importer;
5353
// Backtracking below the package base
5454
['#subpath/sub/../../../belowbase', 'request is not a valid subpath'],
5555
// Percent-encoded slash errors
56-
['#external/subpath/x%2Fy', 'must not include encoded "/"'],
56+
['#external/subpath/x%2Fy', 'must not include encoded "/" or "\\"'],
57+
['#external/subpath/x%5Cy', 'must not include encoded "/" or "\\"'],
5758
// Target must have a name
5859
['#', '#'],
5960
// Initial slash target must have a leading name
6061
['#/initialslash', '#/initialslash'],
6162
// Percent-encoded target paths
62-
['#percent', 'must not include encoded "/"'],
63+
['#encodedslash', 'must not include encoded "/" or "\\"'],
64+
['#encodedbackslash', 'must not include encoded "/" or "\\"'],
6365
]);
6466

6567
for (const [specifier, expected] of invalidImportSpecifiers) {
Collapse file

‎test/es-module/test-esm-pkgname.mjs‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-pkgname.mjs
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ importFixture('as%2Ff').catch(mustCall((err) => {
77
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
88
}));
99

10+
importFixture('as%5Cf').catch(mustCall((err) => {
11+
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
12+
}));
13+
1014
importFixture('as\\df').catch(mustCall((err) => {
1115
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
1216
}));
Collapse file

‎test/fixtures/es-modules/pkgimports/package.json‎

Copy file name to clipboardExpand all lines: test/fixtures/es-modules/pkgimports/package.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"#": "./test.js",
2626
"#/initialslash": "./test.js",
2727
"#notfound": "./notfound.js",
28-
"#percent": "./..%2F/x.js"
28+
"#encodedslash": "./..%2F/x.js",
29+
"#encodedbackslash": "./..%5C/x.js"
2930
}
3031
}
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default ',';

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.