Permalink
Browse files

module: allow loading files with % in the name

PR-URL: #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>
  • Loading branch information...
guybedford authored and targos committed Oct 10, 2017
1 parent f753aed commit 86082a4a749662185a2ec8e0968e19fc6ffee05e
View
@@ -1378,8 +1378,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;
}
@@ -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;
@@ -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';

0 comments on commit 86082a4

Please sign in to comment.