Repository navigation
fix(javascript): keep empty URL path segments significant - #3792
Conversation
ESM imports and HTML script references were joined with POSIX path rules, which collapse '//' before applying '..'. URL resolution removes the empty segment instead, so './assets//../app.js' names assets/app.js, not app.js, and the graph linked the importer and renderer to the wrong file. URL references refused every '//' even when dot segments cancel it. Resolve ESM, HTML (including document base) and URL references through one URL dot-segment helper. A remaining empty segment stays unavailable, references above the artifact root are still rejected, and CommonJS keeps filesystem path semantics. Fixes #3307 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; both previous findings are fixed and no new blocking issue was found. SummaryThe PR gives ESM, HTML, and URL references shared URL-path rules while leaving CommonJS filesystem rules unchanged.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[HTML document directory] --> B[Apply base href]
B --> C[Keep segments and escape count]
C --> D[Remove final base segment]
D --> E[Apply script reference]
E --> F[Reject remaining empty segments]
F --> G[Check artifact root]
G --> H[Look up exact file]
Reviews (2) · Last reviewed commit: "fix(javascript): resolve HTML base and r..." · Reviewed by Greptile |
The base href was turned into a canonical path before the script reference was applied. A base empty segment that the reference's '..' would remove was rejected early, and an above-root '..' from the base became a removable segment that the reference's '..' could cancel. Keep one URL path state through base and reference resolution, with above-root escapes held apart from removable segments, and reject empty segments only in the final path. Remove the superseded htmlBaseDirectory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #3307
Root cause
JavaScriptArtifactPathResolutionjoined ESM relative imports and HTML script references (including the document base) withposix.join. POSIX normalization collapses//before it applies.., so./assets//../app.jsbecameapp.js. Under URL semantics, which is how both ESM and HTML resolve,..removes the preceding empty segment, givingassets/app.js. When both files existed, the graph linked the importer and the renderer to the wrong file and still reportedresolvedwith complete coverage. URL references had the opposite problem: they refused every//, even when dot segments cancel it to an exact path.Change
There is now one owner for URL-path candidates,
urlRelativeCandidate(directory, reference):.is dropped, and..pops the previous segment even when it is empty../assets//app.js, staysunavailable, with the existing "Repeated URL path separators…" limitation. A trailing empty segment is directory form and is handled by the existing exact-file check...candidate, soconfineCandidaterejects it as before.ESM imports (
module-specifier+import), HTML references (with and without<base href>, including the base itself) and URL references all use it. CommonJSrequireand runtime entrypoints keep filesystem path semantics. The docs (javascript-artifact-reconstruction.md) state the rule.Validation
The issue's public CLI repro (
index.html,main.mjs,main.cjs; bothapp.jsandassets/app.jsexist):index.htmlmodule scriptapp.js(wrong)assets/app.jsmain.mjsESM importapp.js(wrong)assets/app.jsmain.cjsrequireapp.jsapp.js(unchanged, filesystem semantics)Each target matches
new URL(…)and Node's CommonJS resolver respectively. Output grows from 70,675 to 70,696 B, from the longer resolved paths.Real applications, CLI on an older
mainbuild vs this PR:app.asar: normalized output identical (108,108,885 B both; 15.2 s vs 14.3 s).app.asar(--integrity-policy record-and-continue): equivalent once host-budget numbers are erased and hash ordering is ignored (125.8 MB both; 41.3 s vs 38.3 s).These bundles contain no
//references, so nothing changes for them.Tests:
keeps empty URL path segments significantreplacesdoes not collapse empty URL path segments. Each case is checked againstnew URLfirst, then acrossurl-reference,html-reference, ESMimportand CommonJSrequire../nested//worker.jsstays unresolved for the URL contexts../nested//../worker.jsresolves todist/nested/worker.jsfor the URL contexts and todist/worker.jsforrequire.mainfor both cases; I checked by restoring main's resolver.npm run check:fastandnpm run docs:check.Behavior change to note: URL references such as
new URL("./nested//../worker.js", import.meta.url)previously stayed unresolved. They now resolve to the exact URL target, matching the HTML and ESM contexts and the URL parser.🤖 Generated with Claude Code