From c727fe467d190996355f253da56f2e897ce1c56d Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 6 Nov 2024 16:34:11 +0100 Subject: [PATCH] feat(js): Read debug IDs from debugId field Companion PR to https://github.com/getsentry/rust-sourcemap/pull/97. This adjusts `discover_sourcemap_embedded_debug_id` so that it finds debug IDs at both `"debug_id"` and `"debugId"`. --- symbolic-debuginfo/src/js.rs | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/symbolic-debuginfo/src/js.rs b/symbolic-debuginfo/src/js.rs index d47c8897..3356a702 100644 --- a/symbolic-debuginfo/src/js.rs +++ b/symbolic-debuginfo/src/js.rs @@ -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 { #[derive(Deserialize)] struct DebugIdInSourceMap { + #[serde(alias = "debugId")] debug_id: Option, } @@ -49,3 +52,42 @@ pub fn discover_debug_id(contents: &str) -> Option { } 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()) + ); + } +}