Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- (sourcemaps) Skip non-base64 embedded sourcemaps during injection ([#3243](https://github.com/getsentry/sentry-cli/pull/3243))

### New Features ✨

- Add `sentry-cli build download` command to download installable builds (IPA/APK) by build ID ([#3221](https://github.com/getsentry/sentry-cli/pull/3221)).
Expand Down
7 changes: 6 additions & 1 deletion src/utils/sourcemaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,12 @@ impl SourceMapProcessor {

let Ok(mut decoded) = data_encoding::BASE64.decode(encoded.as_bytes())
else {
bail!("Invalid embedded sourcemap in source file {source_url}");
// The data URL isn't valid base64, so we can't use it.
// This commonly happens when minified bundles contain
// sourceMappingURL strings inside template literals
// (e.g from bundled terser or babel)
warn!("Skipping {source_url}: embedded sourcemap is not valid base64");
continue;
};

let mut sourcemap =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var x = 1 + 2;
var output =
code +
`
//# sourceMappingURL=data:application/json;base64,` +
btoa(json);
console.log(x);
23 changes: 23 additions & 0 deletions tests/integration/sourcemaps/inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,29 @@ fn command_sourcemaps_inject_malformed_map() {
);
}

#[test]
fn command_sourcemaps_inject_sourcemap_url_in_string_literal() {
// When tools like terser or babel are bundled into a worker, their minified
// code contains string concatenations that produce sourceMappingURL comments.
// After minification these can land at column 0, making them look like real
// sourcemap directives. sentry-cli should not treat them as embedded
// sourcemaps and should not fail.
let testcase_cwd_path =
"tests/integration/_cases/sourcemaps/sourcemaps-inject-sourcemap-in-string-literal.in/";
if std::path::Path::new(testcase_cwd_path).exists() {
remove_dir_all(testcase_cwd_path).unwrap();
}
copy_recursively(
"tests/integration/_fixtures/inject_sourcemap_in_string_literal/",
testcase_cwd_path,
)
.unwrap();

TestManager::new()
.assert_cmd(vec!["sourcemaps", "inject", testcase_cwd_path])
.run_and_assert(AssertCommand::Success);
}

/// Recursively assert that the contents of two directories are equal.
///
/// We only support directories that contain exclusively text files.
Expand Down
Loading