From b3d4ff94596a8f572c46fb6969df2fba76abe3d0 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Thu, 7 Nov 2024 11:22:39 +0100 Subject: [PATCH] feat(js): Read debug IDs from debugId field (#874) This adjusts discover_sourcemap_embedded_debug_id so that it finds debug IDs at both "debug_id" and "debugId". --- CHANGELOG.md | 8 +++++-- symbolic-debuginfo/src/js.rs | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbd376d16..0d6a14923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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))". diff --git a/symbolic-debuginfo/src/js.rs b/symbolic-debuginfo/src/js.rs index d47c88971..3356a7027 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()) + ); + } +}