Skip to content

Commit

Permalink
percent-encoded target test
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 4, 2020
1 parent 8fe68f7 commit 1dc83f5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -2787,4 +2787,4 @@ such as `process.stdout.on('data')`.
[vm]: vm.html
[self-reference a package using its name]: esm.html#esm_self_referencing_a_package_using_its_name
[define a custom subpath]: esm.html#esm_subpath_exports
["imports" field]: esm.html#internal_package_imports
["imports" field]: esm.html#esm_internal_package_imports
4 changes: 2 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
try {
return fileURLToPath(resolved);
} catch (err) {
if (err.code === 'ERR_INVALID_FILE_URL_PATH' &&
StringPrototypeIncludes(err.message, 'must not include encoded "/" characters')) {
if (err.code === 'ERR_INVALID_FILE_URL_PATH' && StringPrototypeIncludes(
err.message, 'must not include encoded "/" characters')) {
throw new ERR_INVALID_MODULE_SPECIFIER(
resolved.pathname, 'must not include encoded "/" characters',
fileURLToPath(baseUrl));
Expand Down
3 changes: 2 additions & 1 deletion test/es-module/test-esm-imports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const { requireImport, importImport } = importer;
['#', '#'],
// Initial slash target must have a leading name
['#/initialslash', '#/initialslash'],
// Percent-encoded target paths
['#percent', 'must not include encoded "/"'],
]);

for (const [specifier, expected] of invalidImportSpecifiers) {
Expand All @@ -81,7 +83,6 @@ const { requireImport, importImport } = importer;

for (const specifier of undefinedImports) {
loadFixture(specifier).catch(mustCall((err) => {
console.log(err);
strictEqual(err.code, 'ERR_PACKAGE_IMPORT_NOT_DEFINED');
assertStartsWith(err.message, 'Package import ');
assertIncludes(err.message, specifier);
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/es-modules/pkgimports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"#subpath/nullshadow/": [null],
"#": "./test.js",
"#/initialslash": "./test.js",
"#notfound": "./notfound.js"
"#notfound": "./notfound.js",
"#percent": "./..%2F/x.js"
}
}

0 comments on commit 1dc83f5

Please sign in to comment.