From 1c338b3ea64fdfaab431a286f03380ebeaf8237b Mon Sep 17 00:00:00 2001 From: mtlcl410 <2368091+mtlcl410@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:48:53 +0800 Subject: [PATCH] M8: a phone number takes one slash, right after its area code (#3205) Review follow-up: "0426/12/3456" and "0426 12/3456" matched, since any slash between digits counted. Only one slash is allowed now, and only right after the first (area code) group. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Gv2WwdgjmBz33GWkwgNn3Q --- crates/redact/src/patterns.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/redact/src/patterns.rs b/crates/redact/src/patterns.rs index a7f2bf67b..a476915d4 100644 --- a/crates/redact/src/patterns.rs +++ b/crates/redact/src/patterns.rs @@ -158,8 +158,12 @@ fn phone(s: &[char], i: usize) -> Option { if seps == 0 && !labelled(s, i) || digit(s.get(end)) || run_continues(s, end.checked_sub(1)?, 1, &SEPS) { return None; } - // Only an area code with a trunk 0 takes a slash, so "2024/123456" is no phone number. + // Only an area code with a trunk 0 takes a slash, so "2024/123456" is no phone number; and + // only one, right after it ("0426/123456", not "0426/12/3456" or "0426 12/3456"). let slash = run.contains(&'/'); + if run.iter().filter(|c| **c == '/').count() > 1 || slash && !run.iter().take_while(|c| **c != '/').all(char::is_ascii_digit) { + return None; + } let ok = if plus { // E.164: a `+` country code and up to 15 digits in all ("+49 2151 123456"). !slash && (8..=15).contains(&n) @@ -472,7 +476,7 @@ mod tests { found( Pattern::Phone, "id 0211123456, +4921511234567, hotel 3451234567, prot. 2024/123456, on 01/10/2026, \ - tel. 12345, tel 0426/ 123456, +39 0426/123456" + tel. 12345, tel 0426/ 123456, +39 0426/123456, tel 0426/12/3456, tel 0426 12/3456" ), Vec::::new() );