Skip to content

Commit 38daba8

Browse files
authored
fix(sourcemaps): don't attempt to treat remote URL as a local file path (#1850)
1 parent 791a1f8 commit 38daba8

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

src/utils/sourcemaps.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ fn url_matches_extension(url: &str, extensions: &[&str]) -> bool {
239239
.unwrap_or(false)
240240
}
241241

242+
/// Return true iff url is a remote url (not a local path or embedded sourcemap).
243+
fn is_remote_url(url: &str) -> bool {
244+
return match Url::parse(url) {
245+
Ok(url) => url.scheme() != "data",
246+
Err(_) => false,
247+
};
248+
}
249+
242250
impl SourceMapProcessor {
243251
/// Creates a new sourcemap validator.
244252
pub fn new() -> SourceMapProcessor {
@@ -364,7 +372,14 @@ impl SourceMapProcessor {
364372
continue;
365373
};
366374

367-
let sourcemap_reference = match discover_sourcemaps_location(contents) {
375+
// If this is a full external URL, the code below is going to attempt
376+
// to "normalize" it with the source path, resulting in a bogus path
377+
// like "path/to/source/dir/https://some-static-host.example.com/path/to/foo.js.map"
378+
// that can't be resolved to a source map file.
379+
// Instead, we pretend we failed to discover the location, and we fall back to
380+
// guessing the source map location based on the source location.
381+
let location = discover_sourcemaps_location(contents).filter(|loc| !is_remote_url(loc));
382+
let sourcemap_reference = match location {
368383
Some(url) => SourceMapReference::from_url(url.to_string()),
369384
None => match guess_sourcemap_reference(&sourcemaps, &source.url) {
370385
Ok(target) => target,

tests/integration/_cases/sourcemaps/sourcemaps-inject-split-ambiguous.trycmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ $ sentry-cli sourcemaps inject ./code ./maps ./maps2 --log-level warn
99
> Found 1 file
1010
> Analyzing 5 sources
1111
> Injecting debug ids
12-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] Ambiguous matches for sourcemap path ./code/foo/index.js.map:
13-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] ./maps/foo/index.js.map
14-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] ./maps2/foo/index.js.map
12+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] Ambiguous matches for sourcemap path ./code/foo/index.js.map:
13+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] ./maps/foo/index.js.map
14+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] ./maps2/foo/index.js.map
1515

1616
Source Map Debug ID Injection Report
1717
Modified: The following source files have been modified to have debug ids

tests/integration/_cases/sourcemaps/sourcemaps-inject.trycmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
$ sentry-cli sourcemaps inject ./server ./static
33
? success
44
> Searching ./server
5-
> Found 12 files
5+
> Found 14 files
66
> Searching ./static
77
> Found 8 files
8-
> Analyzing 20 sources
8+
> Analyzing 22 sources
99
> Injecting debug ids
1010

1111
Source Map Debug ID Injection Report
1212
Modified: The following source files have been modified to have debug ids
1313
[..]-[..]-[..]-[..]-[..] - ./server/app/page.js
1414
[..]-[..]-[..]-[..]-[..] - ./server/chunks/1.js
1515
[..]-[..]-[..]-[..]-[..] - ./server/dummy_embedded.js
16+
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js
1617
[..]-[..]-[..]-[..]-[..] - ./server/flight-manifest.js
1718
[..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js
1819
[..]-[..]-[..]-[..]-[..] - ./server/pages/api/hello.js
@@ -21,6 +22,7 @@ Source Map Debug ID Injection Report
2122
[..]-[..]-[..]-[..]-[..] - ./static/chunks/app/head-172ad45600676c06.js
2223
[..]-[..]-[..]-[..]-[..] - ./static/chunks/pages/asdf-05b39167abbe433b.js
2324
Modified: The following sourcemap files have been modified to have debug ids
25+
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js.map
2426
[..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js.map
2527
[..]-[..]-[..]-[..]-[..] - ./static/chunks/575-bb7d7e0e6de8d623.js.map
2628
Ignored: The following source files already have debug ids

tests/integration/_cases/sourcemaps/sourcemaps-upload-some-debugids.trycmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ $ sentry-cli sourcemaps upload tests/integration/_fixtures/upload_some_debugids
55
> Analyzing 20 sources
66
> Rewriting sources
77
> Adding source map references
8-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] Some source files don't have debug ids:
9-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/app/page.js
10-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/chunks/1.js
11-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/dummy_embedded.js
12-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/pages/_document.js
13-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/pages/api/hello.js
14-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/static/chunks/575-bb7d7e0e6de8d623.js
15-
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/static/chunks/pages/asdf-05b39167abbe433b.js
8+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] Some source files don't have debug ids:
9+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/app/page.js
10+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/chunks/1.js
11+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/dummy_embedded.js
12+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/pages/_document.js
13+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/pages/api/hello.js
14+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/static/chunks/575-bb7d7e0e6de8d623.js
15+
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/static/chunks/pages/asdf-05b39167abbe433b.js
1616
> Bundled 20 files for upload
1717
> Bundle ID: [..]-[..]-[..]-[..]-[..]
1818
> Uploaded files to Sentry

tests/integration/_fixtures/inject/server/dummy_hosted.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/_fixtures/inject/server/dummy_hosted.js.map

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)