summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-problem-report/src/lib.rs31
1 files changed, 27 insertions, 4 deletions
diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs
index b5fdadc2fe..a9bdf79051 100644
--- a/mullvad-problem-report/src/lib.rs
+++ b/mullvad-problem-report/src/lib.rs
@@ -420,10 +420,7 @@ impl ProblemReport {
}
fn redact_home_dir(input: &str) -> Cow<'_, str> {
- match dirs_next::home_dir() {
- Some(home) => Cow::from(input.replace(home.to_string_lossy().as_ref(), "~")),
- None => Cow::from(input),
- }
+ redact_home_dir_inner(input, dirs_next::home_dir())
}
fn redact_network_info(input: &str) -> Cow<'_, str> {
@@ -505,6 +502,32 @@ impl ProblemReport {
}
}
+fn redact_home_dir_inner(input: &str, home_dir: Option<PathBuf>) -> Cow<'_, str> {
+ match home_dir {
+ Some(home) => {
+ let out = input.replace(home.to_string_lossy().as_ref(), "~");
+
+ // On Windows, redact the prefix of any path that contains \Users\{user}.
+ #[cfg(target_os = "windows")]
+ {
+ let mut home = home;
+ let prefix = home.components().next();
+ if let Some(prefix @ std::path::Component::Prefix(_)) = prefix.as_ref() {
+ home = home.strip_prefix(prefix).unwrap().to_path_buf();
+ }
+ let expr = format!(r"[\w\\]+{}", regex::escape(&home.display().to_string()));
+ let regex = Regex::new(&expr).unwrap();
+
+ Cow::Owned(regex.replace_all(&out, "~").to_string())
+ }
+
+ #[cfg(not(target_os = "windows"))]
+ Cow::from(out)
+ }
+ None => Cow::from(input),
+ }
+}
+
fn build_mac_regex() -> String {
let octet = "[[:xdigit:]]{2}"; // 0 - ff