diff --git a/.vscode/settings.json b/.vscode/settings.json index 19688e8d4c..43c4507ebf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,6 @@ "eslint.autoFixOnSave": true, "editor.tabSize": 2, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" } } diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index f6cf0cb524..39a113a1b9 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -247,6 +247,19 @@ fn is_remote_url(url: &str) -> bool { }; } +/// Return true if url appears to be a URL path. +/// Most often, a URL path will begin with `/`, +/// particularly in the case of static asset collection and hosting, +/// but such a path is very unlikely to exist in the local filesystem. +fn is_url_path(url: &str) -> bool { + url.starts_with('/') && !Path::new(url).exists() +} + +/// Return true iff url is probably not a local file path. +fn is_remote_sourcemap(url: &str) -> bool { + is_remote_url(url) || is_url_path(url) +} + impl SourceMapProcessor { /// Creates a new sourcemap validator. pub fn new() -> SourceMapProcessor { @@ -378,7 +391,8 @@ impl SourceMapProcessor { // that can't be resolved to a source map file. // Instead, we pretend we failed to discover the location, and we fall back to // guessing the source map location based on the source location. - let location = discover_sourcemaps_location(contents).filter(|loc| !is_remote_url(loc)); + let location = + discover_sourcemaps_location(contents).filter(|loc| !is_remote_sourcemap(loc)); let sourcemap_reference = match location { Some(url) => SourceMapReference::from_url(url.to_string()), None => match guess_sourcemap_reference(&sourcemaps, &source.url) { diff --git a/tests/integration/_cases/sourcemaps/sourcemaps-inject.trycmd b/tests/integration/_cases/sourcemaps/sourcemaps-inject.trycmd index ee8bb6d681..f6957cb51e 100644 --- a/tests/integration/_cases/sourcemaps/sourcemaps-inject.trycmd +++ b/tests/integration/_cases/sourcemaps/sourcemaps-inject.trycmd @@ -2,10 +2,10 @@ $ sentry-cli sourcemaps inject ./server ./static ? success > Searching ./server -> Found 14 files +> Found 16 files > Searching ./static > Found 8 files -> Analyzing 22 sources +> Analyzing 24 sources > Injecting debug ids Source Map Debug ID Injection Report @@ -14,6 +14,7 @@ Source Map Debug ID Injection Report [..]-[..]-[..]-[..]-[..] - ./server/chunks/1.js [..]-[..]-[..]-[..]-[..] - ./server/dummy_embedded.js [..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js + [..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted_full.js [..]-[..]-[..]-[..]-[..] - ./server/flight-manifest.js [..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js [..]-[..]-[..]-[..]-[..] - ./server/pages/api/hello.js @@ -23,6 +24,7 @@ Source Map Debug ID Injection Report [..]-[..]-[..]-[..]-[..] - ./static/chunks/pages/asdf-05b39167abbe433b.js Modified: The following sourcemap files have been modified to have debug ids [..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js.map + [..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted_full.js.map [..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js.map [..]-[..]-[..]-[..]-[..] - ./static/chunks/575-bb7d7e0e6de8d623.js.map Ignored: The following source files already have debug ids diff --git a/tests/integration/_fixtures/inject/server/dummy_hosted.js b/tests/integration/_fixtures/inject/server/dummy_hosted.js index 352cc4e62c..d606080ca8 100644 --- a/tests/integration/_fixtures/inject/server/dummy_hosted.js +++ b/tests/integration/_fixtures/inject/server/dummy_hosted.js @@ -1 +1 @@ -//# sourceMappingURL=https://some-static-hosting.example.com/path/to/dummy_embedded.js.map +//# sourceMappingURL=/path/to/dummy_embedded.js.map diff --git a/tests/integration/_fixtures/inject/server/dummy_hosted_full.js b/tests/integration/_fixtures/inject/server/dummy_hosted_full.js new file mode 100644 index 0000000000..352cc4e62c --- /dev/null +++ b/tests/integration/_fixtures/inject/server/dummy_hosted_full.js @@ -0,0 +1 @@ +//# sourceMappingURL=https://some-static-hosting.example.com/path/to/dummy_embedded.js.map diff --git a/tests/integration/_fixtures/inject/server/dummy_hosted_full.js.map b/tests/integration/_fixtures/inject/server/dummy_hosted_full.js.map new file mode 100644 index 0000000000..648aa29a7b --- /dev/null +++ b/tests/integration/_fixtures/inject/server/dummy_hosted_full.js.map @@ -0,0 +1,9 @@ +{ + "version": 3, + "file": "1.js", + "mappings": ";;;", + "sources": [], + "sourcesContent": [], + "names": [], + "sourceRoot": "" +}