YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(pii): email regex matched a literal '|' in the TLD (#4122)
Louis Beaumontf6ffb988bf51
diff --git a/crates/screenpipe-core/src/pii_removal.rs b/crates/screenpipe-core/src/pii_removal.rsindex 7c5a7418e..5fc54faf7 100644--- a/crates/screenpipe-core/src/pii_removal.rs+++ b/crates/screenpipe-core/src/pii_removal.rs@@ -12,7 +12,10 @@ lazy_static! {(Regex::new(r"\b\d{3}-\d{2}-\d{4}\b").unwrap(), "SSN"),// Contact info- (Regex::new(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b").unwrap(), "EMAIL"),+ // TLD is letters only. `[A-Z|a-z]` was a bug: inside a character class+ // `|` is a literal, so it also matched a pipe in the TLD (e.g. "a.c|m"),+ // producing spurious EMAIL hits. `[A-Za-z]` is the intended set.+ (Regex::new(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b").unwrap(), "EMAIL"),// Phone numbers - require formatting to distinguish from numeric IDs (#2340):// +1-234-567-8901, (234) 567-8901, 234-567-8901, 234.567.8901, +12345678901@@ -368,6 +371,18 @@ mod tests {assert!(!contains_pii("not an email"));}+ #[test]+ fn test_email_tld_is_letters_only() {+ // Regression: the TLD class previously included a literal `|`+ // (`[A-Z|a-z]`), so a pipe in the TLD position was treated as an email.+ assert!(!contains_pii("[email protected]|m"));+ assert!(!contains_pii("[email protected]|b"));+ assert_eq!(get_pii_type("[email protected]|m"), None);+ // Genuine emails must still be detected.+ assert!(contains_pii("[email protected]"));+ assert!(contains_pii("[email protected]"));+ }+#[test]fn test_get_pii_type() {assert_eq!(