mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
module: allow loading files with % in the name
PR-URL: https://github.com/nodejs/node/pull/16128 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Bradley Meck <bradley.meck@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
2b0145d47c
commit
d90dca6620
@ -1377,8 +1377,14 @@ function getPathFromURL(path) {
|
||||
return isWindows ? getPathFromURLWin32(path) : getPathFromURLPosix(path);
|
||||
}
|
||||
|
||||
// We percent-encode % character when converting from file path to URL,
|
||||
// as this is the only character that won't be percent encoded by
|
||||
// default URL percent encoding when pathname is set.
|
||||
const percentRegEx = /%/g;
|
||||
function getURLFromFilePath(filepath) {
|
||||
const tmp = new URL('file://');
|
||||
if (filepath.includes('%'))
|
||||
filepath = filepath.replace(percentRegEx, '%25');
|
||||
tmp.pathname = filepath;
|
||||
return tmp;
|
||||
}
|
||||
|
7
test/es-module/test-esm-double-encoding-native%20.js
Normal file
7
test/es-module/test-esm-double-encoding-native%20.js
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
|
||||
// Trivial test to assert we can load files with `%` in their pathname.
|
||||
// Imported by `test-esm-double-encoding.mjs`.
|
||||
|
||||
module.exports = 42;
|
6
test/es-module/test-esm-double-encoding.mjs
Normal file
6
test/es-module/test-esm-double-encoding.mjs
Normal file
@ -0,0 +1,6 @@
|
||||
// Flags: --experimental-modules
|
||||
import '../common';
|
||||
|
||||
// Assert we can import files with `%` in their pathname.
|
||||
|
||||
import './test-esm-double-encoding-native%2520.js';
|
Loading…
Reference in New Issue
Block a user