Repository navigation
fix(core): percent-encode resolved file URLs - #847
Conversation
The resolve hook turned the resolver's path back into a `file:` URL without percent-encoding it, so Node read a raw `#` as a fragment, `?` as a query and `%XX` as an escape, and loaded a different file (exit code 0) or none. Encode the path with the exact set `pathToFileURL` uses on POSIX and on the Windows drive form, then append the query and fragment verbatim. Also make URL references round trip through the resolver: decode percent-encoded ESM relative specifiers, escape a decoded `#` for the resolver (resolving from the parent directory when the path is not ASCII or holds `?`), leave encoded separators (`%2F`, `%5C`) to Node so it still raises ERR_INVALID_MODULE_SPECIFIER, and escape `#` during tsconfig discovery. Closes #837 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 171ce8c336
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A relative specifier or file URL holding `%zz`, or an escape that does not decode to UTF-8 (`%FF`), was resolved verbatim and loaded a file literally named `a%zz.ts`, where Node throws `URIError: URI malformed`. Hand such specifiers to Node's own resolution instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37dc6ed1b7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
`//host/…/a%20b.ts` is a URL network-path reference whose first segment is the file URL host; Node rejects it with ERR_INVALID_FILE_URL_HOST. The escape-decoding branch read it as a local path and loaded `/host/…/a b.ts`. Only decode single-slash absolute paths. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d494bcee3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The URL parser reads `\` as `/` in file URLs, so `./dir\foo%20bar.ts` names `dir/foo bar.ts`. The resolver read it as a POSIX file-name character, picked a file literally named `dir\foo bar.ts`, and Node then rejected its `%5C` URL. Normalize raw backslashes in ESM relative and absolute-path specifiers and in POSIX file URLs; CommonJS `require` keeps its literal reading. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Closes #856 ## Problem In an ES module import, `#` starts a URL fragment: Node.js resolves `import './a#b.ts'` as `./a` with the fragment `#b.ts`. Since #847, oxc-node loaded a file named `a#b.ts` instead, whenever one existed. oxc_resolver follows enhanced-resolve: for a specifier with a `#` and no `?`, `load_parse` first tries the whole specifier as a path. #847 re-attached the raw `?query#fragment` to the resolver's specifier, so `file:` URLs with a fragment were affected the same way. ## Fix A URL reference's query and fragment never reach the resolver now. A URL reference is a `file:` URL, or a relative or absolute-path specifier in ESM. Its decoded pathname is resolved on its own, and the raw suffix is appended to the resolved URL, as Node.js does. `resolver_request` no longer takes a suffix. `require()` is unaffected: `register.mjs` hands every `require()` request (no `importAttributes`) to Node.js' own CommonJS resolution before `createResolve` runs, so `#` and `%` stay file-name characters there. The request kind isn't inferred from the `require` condition, which `--conditions=require` adds to imports too. ## Verification Module URLs match plain Node exactly: `./url.mjs#one` gives `…/url.mjs#one`, `./url.mjs?q#two` gives `…/url.mjs?q#two`, and an encoded `./a%23b.mjs` still loads `a#b.mjs`. ## Tests - The `resolver_request` unit test is updated for the new signature. - `percent-encoded-paths.spec.ts` gains a block for #856: - a relative import and a `file:` URL with `#` skip the decoy `a#b.ts`; - the query and fragment are kept on the module URL; - an encoded `%23` still names the file; - an import under `--conditions=require` still reads `#` as a fragment; - `require()` keeps `#` and `%` as file-name characters. The `#` cases fail without the change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Closes #837
Problem
The resolve hook turned the resolver's path back into a
file:URL without percent-encoding it: POSIXoxc_resolved_path_to_urlwrotefile://{path}raw, and the Windows drive-letter branch ofpath_to_urldid too. Node then read a raw#as a fragment,?as a query and%XXas an escape. It loaded a different file and exited 0, or found no file at all.Fix
encode_file_url_path): uses exactly the encode setpathToFileURLuses, on POSIX and on the Windows drive form, with the drive:kept literal. Windows UNC paths share the same encoder. The resolution's query and fragment are appended verbatim. They already carry their leading?/#, so the old Windows code that pushed an extra?/#is gone.file_url_to_pathdrops?query/#fragmentbefore decoding.%are decoded before resolving.#is passed to the resolver with its\0#escape. Two cases resolve the file name from its parent directory instead: a path holding?, and a non-ASCII path holding#. oxc_resolver has no escape for?and drops the\0#escape byte by byte, mangling multi-byte characters.%2F,%5C) are never decoded and go to Node, which still raisesERR_INVALID_MODULE_SPECIFIER. Without this, decoding made./a%2Fb.tsruna/b.ts.#for ASCII paths.find_tsconfigparses its argument as a specifier, so compiler options were ignored for files underp#1/.Tests
pathToFileURLoutput (POSIX and Windows drive form), and cover suffix appending, round trips, encoded-separator detection andresolver_request.packages/integrate-vitest/__tests__/percent-encoded-paths.spec.tscreates the fixtures at run time, because#and%file names are awkward to commit. Every case has a decoy, and the assertions check stdout, not just the exit code.Verification (macOS arm64, Node 24.22)
42. So do 21 more:?in a file name,%in a directory name, relative, JSON,?v=1#xand.ctsimports from inside#directories, andimport.meta.url, which matches plain Node.cargo test --all-features,cargo clippy --all-targets --all-features -- -D warnings,vp run test(202 passed) andvp run lintall pass.Known limits (need oxc_resolver changes)
?, or holding#next to non-ASCII text, still falls back to Node's own resolution.?.🤖 Generated with Claude Code