Skip to content

Commit

Permalink
fix(js): Resolve conflict between "debugId" and "debug_id" (#877)
Browse files Browse the repository at this point in the history
Using an alias causes deserialization to fail when
both keys are set. Therefore we now read both fields
and implement the logic explicitly.
  • Loading branch information
loewenheim authored Nov 26, 2024
1 parent e08c803 commit 0277066
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
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**
- js: Fixed an error when reading debug IDs from sourcemaps with
both `"debugId"` and `"debug_id"` keys ([#877](https://github.com/getsentry/symbolic/pull/877)).

## 12.12.1

**Features**:
Expand Down
30 changes: 26 additions & 4 deletions symbolic-debuginfo/src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,22 @@ 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.
/// Both `debugId` and `debug_id` are supported as field names. If both
/// are set, the former takes precedence.
pub fn discover_sourcemap_embedded_debug_id(contents: &str) -> Option<DebugId> {
// Deserialize from `"debugId"` or `"debug_id"`,
// preferring the former.
#[derive(Deserialize)]
struct DebugIdInSourceMap {
#[serde(alias = "debugId")]
debug_id: Option<DebugId>,
#[serde(rename = "debugId")]
debug_id_new: Option<DebugId>,
#[serde(rename = "debug_id")]
debug_id_old: Option<DebugId>,
}

serde_json::from_str(contents)
.ok()
.and_then(|x: DebugIdInSourceMap| x.debug_id)
.and_then(|x: DebugIdInSourceMap| x.debug_id_new.or(x.debug_id_old))
}

/// Parses a `debugId` comment in a file to discover a sourcemap's debug ID.
Expand Down Expand Up @@ -90,4 +95,21 @@ mod tests {
Some(DebugId::default())
);
}

#[test]
fn test_debugid_both() {
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",
"debug_id":"11111111-1111-1111-1111-111111111111"
}"#;

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

0 comments on commit 0277066

Please sign in to comment.