Skip to content

Commit

Permalink
feat(js): Read debug IDs from debugId field
Browse files Browse the repository at this point in the history
Companion PR to getsentry/rust-sourcemap#97.
This adjusts `discover_sourcemap_embedded_debug_id` so that
it finds debug IDs at both `"debug_id"` and `"debugId"`.
  • Loading branch information
loewenheim committed Nov 6, 2024
1 parent 5d4e750 commit c727fe4
Showing 1 changed file with 42 additions and 0 deletions.
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 c727fe4

Please sign in to comment.