Skip to content

Error importing ES module with an encoded comma in the URL #40305

Description

@fasttime

Version

v16.10.0

Platform

No response

Subsystem

No response

What steps will reproduce the bug?

// test.mjs
import './foo%2cbar.mjs';

or

// test2.mjs
await import('./foo%2cbar.mjs');

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?

Should import a module named "foo,bar.mjs" located in the same folder, if present, or throw an error with code ERR_MODULE_NOT_FOUND.

What do you see instead?

Throws:

TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "./foo%2cbar.mjs" must not include encoded "/" or "\" characters imported from ./test.mjs

Note that there is no encoded "/" or "\" in "./foo%2cbar.mjs", just an encoded ","!

Additional information

In my understanding, this behavior results from a bug in lib/internal/modules/esm/resolve.js, where the regular expression encodedSepRegEx incorrectly matches an encoded slash or comma ("/" or ",") instead of a slash or backslash.

Activity

targos commented on Oct 4, 2021

@targos
Member

Thanks for the report @fasttime. Would you like to do a PR to fix it?

added
confirmed-bugIssues and PRs for confirmed bugs.
esmIssues and PRs related to the ECMAScript Modules implementation.
on Oct 4, 2021

fasttime commented on Oct 4, 2021

@fasttime
ContributorAuthor

@targos Sure. Thanks for confirming.

added a commit that references this issue on Oct 23, 2021
81cd7f3
added a commit that references this issue on Nov 23, 2021
881dd7b
added a commit that references this issue on May 22, 2026
8ac9aef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.esmIssues and PRs related to the ECMAScript Modules implementation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions