Skip to content

Commit

Permalink
feat(js): Read debug IDs from debugId field (#874)
Browse files Browse the repository at this point in the history
This adjusts discover_sourcemap_embedded_debug_id so that it finds debug IDs at both "debug_id" and "debugId".
  • Loading branch information
loewenheim authored Nov 7, 2024
1 parent 5d4e750 commit b3d4ff9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 12.12.0
## Unreleased

**Features**:
- feat(js): Sourcemap debug IDs can now be read from the `"debugId"` field in addition to
`"debug_id"` ([#870](https://github.com/getsentry/symbolic/pull/870)).

### Various fixes & improvements
## 12.12.0

**Fixes**
- Unship "Support for DWARFv5 embedded source code extension ([#849](https://github.com/getsentry/symbolic/pull/849))".
Expand Down
42 changes: 42 additions & 0 deletions symbolic-debuginfo/src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ pub fn discover_sourcemaps_location(contents: &str) -> Option<&str> {
}

/// Quickly reads the embedded `debug_id` key from a source map.
///
/// Both `debug_id` and `debugId` are supported as field names.
pub fn discover_sourcemap_embedded_debug_id(contents: &str) -> Option<DebugId> {
#[derive(Deserialize)]
struct DebugIdInSourceMap {
#[serde(alias = "debugId")]
debug_id: Option<DebugId>,
}

Expand All @@ -49,3 +52,42 @@ pub fn discover_debug_id(contents: &str) -> Option<DebugId> {
}
None
}

#[cfg(test)]
mod tests {
use debugid::DebugId;

use crate::js::discover_sourcemap_embedded_debug_id;

#[test]
fn test_debugid_snake_case() {
let input = r#"{
"version":3,
"sources":["coolstuff.js"],
"names":["x","alert"],
"mappings":"AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM",
"debug_id":"00000000-0000-0000-0000-000000000000"
}"#;

assert_eq!(
discover_sourcemap_embedded_debug_id(input),
Some(DebugId::default())
);
}

#[test]
fn test_debugid_camel_case() {
let input = r#"{
"version":3,
"sources":["coolstuff.js"],
"names":["x","alert"],
"mappings":"AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM",
"debugId":"00000000-0000-0000-0000-000000000000"
}"#;

assert_eq!(
discover_sourcemap_embedded_debug_id(input),
Some(DebugId::default())
);
}
}

0 comments on commit b3d4ff9

Please sign in to comment.