Repository navigation
fix(javascript): match source-map originals that name parent directories #1215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
N0zoM1z0
merged 9 commits into
morluto:main
from
jayhemnani9910:fix/source-map-parent-paths
Oct 9, 2026
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50642d0
fix(javascript): match source-map originals that name parent directories
jayhemnani9910 b48702a
fix(javascript): resolve parent segments against the source map's dir…
jayhemnani9910 75f0c9d
fix(javascript): resolve source originals against their map location
morluto 819579c
fix(javascript): preserve URI and empty source map path semantics
morluto 10b7706
fix(javascript): separate source URL paths from opaque URI payloads
morluto 3c31882
fix(javascript): preserve filesystem names during URI classification
morluto 0118c44
style(javascript): format source URI presence guard
morluto c2a9dde
fix(javascript): resolve source map references with URL semantics
morluto 89fd82d
fix(javascript): preserve literal UNC source map paths
morluto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(javascript): resolve source map references with URL semantics
- Loading branch information
commit c2a9dde0cc3d98a465beb238927f016ac4b9e396
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { posix } from "node:path"; | ||
| import { fileURLToPath, pathToFileURL } from "node:url"; | ||
|
|
||
| interface SourceMapPath { | ||
| readonly value: string; | ||
| readonly scope: "artifact-relative" | "suffix"; | ||
| } | ||
|
|
||
| /** Resolve a source-map URL reference without changing its recorded identity. */ | ||
| export const resolveJavaScriptSourceMapPath = ( | ||
| source: string, | ||
| mapPath?: string, | ||
| ): SourceMapPath | null => { | ||
| const portable = source.replaceAll("\\", "/"); | ||
| const windowsPath = /^[a-z]:\//iu.test(portable); | ||
| // Preserve parent traversal rather than letting URL resolution clamp at '/'. | ||
| const anchor = `/${"source/".repeat(portable.split("/").length + 1)}`; | ||
| const directory = posix.join( | ||
| anchor, | ||
| posix.dirname(mapPath?.replaceAll("\\", "/") ?? "."), | ||
| ); | ||
| const base = pathToFileURL(`${directory}/`, { windows: false }); | ||
| const absolute = windowsPath | ||
| ? pathToFileURL(source, { windows: true }) | ||
| : URL.parse(source); | ||
| const resolved = windowsPath ? absolute : URL.parse(source, base); | ||
| if ( | ||
| resolved === null || | ||
| !resolved.pathname.startsWith("/") || | ||
| resolved.pathname.endsWith("/") | ||
| ) | ||
| return null; | ||
| const relative = | ||
| absolute === null | ||
| ? !portable.startsWith("/") | ||
| : absolute.href !== resolved.href; | ||
| const path = decodedUrlPath(resolved); | ||
| if (path === null) return null; | ||
| const value = relative | ||
| ? posix.relative(anchor, path) | ||
| : path.replace(/^\/+/, ""); | ||
| if (value === "" || value === ".." || value.startsWith("../")) return null; | ||
| return { | ||
| value, | ||
| scope: relative && mapPath !== undefined ? "artifact-relative" : "suffix", | ||
| }; | ||
| }; | ||
|
|
||
| const decodedUrlPath = (url: URL): string | null => { | ||
| // Encoded separators must not manufacture a different filesystem hierarchy. | ||
| if (/%(?:2f|5c)/iu.test(url.pathname)) return null; | ||
| try { | ||
| if (url.protocol === "file:") | ||
| return fileURLToPath(url, { | ||
| windows: url.hostname !== "" && url.hostname !== "localhost", | ||
| }).replaceAll("\\", "/"); | ||
| return `${url.host}${decodeURIComponent(url.pathname)}`; | ||
| } catch (cause: unknown) { | ||
| if (cause instanceof URIError || cause instanceof TypeError) return null; | ||
| throw cause; | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.