From 93fddd57f4362c622509b0ea8a2b9cb5b691cde5 Mon Sep 17 00:00:00 2001 From: Brett Higgins Date: Thu, 21 Dec 2023 09:57:02 -0500 Subject: [PATCH 1/2] fix: fall back to co-location heuristic if sourcemap url appears to be a remote path Fixes #1870. --- .vscode/settings.json | 2 +- src/utils/sourcemaps.rs | 16 +++++++++++++++- .../_cases/sourcemaps/sourcemaps-inject.trycmd | 6 ++++-- .../_fixtures/inject/server/dummy_hosted.js | 2 +- .../_fixtures/inject/server/dummy_hosted_full.js | 1 + .../inject/server/dummy_hosted_full.js.map | 9 +++++++++ 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tests/integration/_fixtures/inject/server/dummy_hosted_full.js create mode 100644 tests/integration/_fixtures/inject/server/dummy_hosted_full.js.map 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": "" +} From 849e89b91dfa08d779a5035781cea33c64f9d4a3 Mon Sep 17 00:00:00 2001 From: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:04:24 +0200 Subject: [PATCH 2/2] Undo likely-unintentional change --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 43c4507ebf..19688e8d4c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,6 @@ "eslint.autoFixOnSave": true, "editor.tabSize": 2, "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" + "source.fixAll.eslint": true } }