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 8894bdd

Browse filesBrowse files
fasttimerichardlau
authored andcommitted
lib: fix regular expression to detect / and \
PR-URL: #40325 Backport-PR-URL: #40564 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 39583f7 commit 8894bdd
Copy full SHA for 8894bdd

File tree

Expand file treeCollapse file tree

7 files changed

+19
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+19
-5
lines changed
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
@@ -277,7 +277,7 @@ function resolveDirectoryEntry(search) {
277277
return resolveExtensions(new URL('index', search));
278278
}
279279

280-
const encodedSepRegEx = /%2F|%2C/i;
280+
const encodedSepRegEx = /%2F|%5C/i;
281281
function finalizeResolution(resolved, base) {
282282
if (RegExpPrototypeTest(encodedSepRegEx, resolved.pathname))
283283
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
@@ -167,10 +167,13 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
167167
}));
168168
}
169169

170-
// The use of %2F escapes in paths fails loading
170+
// The use of %2F and %5C escapes in paths fails loading
171171
loadFixture('pkgexports/sub/..%2F..%2Fbar.js').catch(mustCall((err) => {
172172
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
173173
}));
174+
loadFixture('pkgexports/sub/..%5C..%5Cbar.js').catch(mustCall((err) => {
175+
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
176+
}));
174177

175178
// Package export with numeric index properties must throw a validation error
176179
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.