diff --git a/crates/symbolicator-js/src/utils.rs b/crates/symbolicator-js/src/utils.rs index f0aa85564..634a3c959 100644 --- a/crates/symbolicator-js/src/utils.rs +++ b/crates/symbolicator-js/src/utils.rs @@ -111,9 +111,17 @@ pub fn fixup_webpack_filename(filename: &str) -> String { } } +/// Returns whether the given abs_path and filename should be considered in-app. +/// +/// This function was originally a simplified (but semantically faithful) version of +/// . +/// For a version that preserves the original exactly (modulo Python -> Rust translation), see +/// `is_in_app_faithful`. pub fn is_in_app(abs_path: &str, filename: &str) -> Option { if abs_path.starts_with("webpack:") { - Some(filename.starts_with("./") && !filename.contains("/node_modules/")) + // This diverges from the original logic. Previously we would only consider + // a filename starting with `./` as in-app, but that seems to be overly strict. + Some(!filename.starts_with("~/") && !filename.contains("/node_modules/")) } else if abs_path.starts_with("app:") { Some(!NODE_MODULES_RE.is_match(filename)) } else if abs_path.contains("/node_modules/") { @@ -718,6 +726,20 @@ mod tests { assert_eq!(is_in_app(abs_path, filename), Some(true)); assert_eq!(is_in_app_faithful(abs_path, filename), Some(true)); + let abs_path = "webpack:///foo/bar/src/App.jsx"; + let filename = "foo/bar/src/App.jsx"; + + // Here we have a discrepancy because the behavior of `is_in_app` + // longer aligns with that of the original Python version. + assert_eq!(is_in_app(abs_path, filename), Some(true)); + assert_eq!(is_in_app_faithful(abs_path, filename), Some(false)); + + let abs_path = "webpack:///./foo/bar/App.tsx"; + let filename = "./foo/bar/src/App.jsx"; + + assert_eq!(is_in_app(abs_path, filename), Some(true)); + assert_eq!(is_in_app_faithful(abs_path, filename), Some(true)); + let abs_path = "webpack:///./node_modules/@sentry/browser/esm/helpers.js"; let filename = "./node_modules/@sentry/browser/esm/helpers.js";