Repository navigation
fix(javascript): keep parent segments that re-enter the synthetic URL root - #7171
devreddy1015 wants to merge 1 commit into
Conversation
… root
Source-map source paths and static new URL(..., import.meta.url) paths
resolve relative references below a deep synthetic root of "source/"
segments, then take posix.relative(root, path). A reference that climbs
above the root and then names "source" (or %73ource) re-creates the
root's own segment, so its parent segments vanish:
- createRequire(new URL("../source/anchor.cjs", import.meta.url)) was
reported as base "anchor.cjs", so require("./dep.cjs") resolved to
app/dep.cjs while Node loads source/dep.cjs.
- A source-map source "../../source/a.js" from maps.js/main.js.map was
reported as the in-artifact path "a.js" instead of unresolved.
pathBelowSyntheticUrlRoot resolves below two roots with different segment
names and keeps the result with more leading parent segments. A reference
cannot re-enter both names at once, and without re-entry both results are
identical. The URL parser still performs all resolution. Module URLs keep
their existing applyUrlReference guard in the application layer, which
these domain modules cannot import.
[Medium impact] The PR appears safe to merge; no actionable code issues were found. SummaryPreserves leading
Tests were inspected, not run during this review. Supersession could not be checked because GitHub authentication was unavailable. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Static source-relative URL] --> C[Resolve below source and anchor roots]
B[Relative source-map reference] --> C
C --> D[Keep the path with more leading parent segments]
D --> E[Static analysis retains the relative path]
D --> F[Source-map matching rejects paths outside the artifact]
Reviews (1) · Last reviewed commit: "fix(javascript): keep parent segments th..." · Reviewed by Greptile |
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. |
|
TL;DR: I ran the PR's 2 changed test files on Node 22.23.4, 24.22.1 and 26.12.1, and all 74 tests passed each time. The Findings
Not run
Test setupCommandsnpm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- tests/acceptance/applications/createRequireFilenameBase.test.ts tests/boundary/filesystem/sourceToBundlePaths.test.ts🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
|
The synthetic-root traversal fix for both createRequire and source-map paths landed in #12161, with regression coverage for same-named re-entry. Thanks for the original report and fix. |
Summary
Relative URLs that climb above their base with
..and then re-enter a directory namedsourcelose their parent segments in two places:createRequire(new URL("../source/anchor.cjs", import.meta.url))was reported as baseanchor.cjs, sorequire("./dep.cjs")resolved toapp/dep.cjs. Node loadssource/dep.cjs.../../source/a.jsfrommaps.js/main.js.mapwas reported as the in-artifact patha.jsinstead of unresolved.Cause and change
Both sites resolve under a synthetic root made of
source/segments, then callposix.relative. A reference that namessource(or%73ource) re-enters that root, and its parent segments vanish. The newpathBelowSyntheticUrlRootresolves under two differently named roots and keeps the result with more leading... A reference cannot re-enter both, and the URL parser still does all resolution. Module URLs already have this guard (applyUrlReferencein the application layer), but domain code cannot import it.Evidence
createRequireFilenameBase.test.tsruns through CLI and stdio MCP with a real Node control. Two new rows are insourceToBundlePaths.test.ts. All of them fail without the fix and pass with it.src/domain/javascriptandsrc/application/javascript: 4,805 tests pass. 319 of 326 related boundary and acceptance files pass. The other 7 fail locally for environment reasons: Node 26 instead of the pinned 24, and missing generated files. The Node SEA one also fails without this change.npm run check:fastpasses.Scope: a static analysis fix within existing boundaries, with no CLI/MCP contract, package or metadata change.
Author readiness
Human owner: @devreddy1015
Before merge
type(scope): outcome.