Skip to content
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

fix: Strip query strings and fragments from sourcemap URLs #809

Merged
merged 4 commits into from
Sep 6, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Fixes**

- `discover_sourcemaps_location` returns source mapping URLs without query parameters or fragments ([#809](https://github.com/getsentry/symbolic/pull/809))

## 12.3.0

**Features**
Expand Down
13 changes: 12 additions & 1 deletion symbolic-debuginfo/src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ use debugid::DebugId;
use serde::Deserialize;

/// Parses a sourceMappingURL comment in a file to discover a sourcemap reference.
///
/// Any query string or fragments the URL might contain will be stripped away.
pub fn discover_sourcemaps_location(contents: &str) -> Option<&str> {
for line in contents.lines().rev() {
if line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=") {
return Some(line[21..].trim());
let url = line[21..].trim();

// The URL might contain a query string or fragment. Strip those away before recording the URL.
let without_query = url.split_once('?').map(|x| x.0).unwrap_or(url);
let without_fragment = without_query
.split_once('#')
.map(|x| x.0)
.unwrap_or(without_query);

return Some(without_fragment);
}
}
None
Expand Down
Loading