Summary
Replace the hand-rolled, NANP-only phone number regex in phileas-python with detection backed by the phonenumbers package (the Python port of Google's libphonenumber), matching what the Java Phileas already does. This closes the international-phone detection gap.
Background
phileas/filters/phone_number_filter.py detects with a set of North-American Numbering Plan regex patterns (optional +1, strict 3-3-4). Numbers in other formats ship unredacted: +44 20 7946 0958, +33 1 42 68 53 00, +91 98765 43210, +49 30 901820, and national-format foreign numbers all fail the patterns. phonenumbers is not currently a dependency.
This is the same fidelity gap that was found in the .NET runtime (its regex-only phone filter). The Java Phileas already avoids it: it detects via libphonenumber (PhoneNumberUtil.findNumbers(input, "US", Leniency.POSSIBLE, ...)). The fix is to bring phileas-python to the same footing.
Proposed change
- Add
phonenumbers as a dependency.
- Detect phone numbers with
phonenumbers.PhoneNumberMatcher(text, region, leniency=Leniency.POSSIBLE) (default region "US"), mirroring the Java filter: +-prefixed international numbers are found regardless of region, and bare national-format numbers are found for the default region.
- This is not a regex swap:
PhoneNumberMatcher is a scanner. Introduce a matcher-based phone filter rather than editing the pattern list. Retain the existing regex only if needed as a fallback for parity; otherwise remove it.
- Keep behavior aligned with the Java filter (same default region and leniency) so the runtimes converge.
Relationship to #48
This is the prerequisite for #48 (support the phone number filter region property). Once detection runs through phonenumbers, #48 makes the default region configurable per policy (string or array). This issue closes the international-detection gap on its own, with the region still hardcoded to "US" (matching Java today).
Acceptance criteria
Unblocks #48.
Summary
Replace the hand-rolled, NANP-only phone number regex in phileas-python with detection backed by the
phonenumberspackage (the Python port of Google's libphonenumber), matching what the Java Phileas already does. This closes the international-phone detection gap.Background
phileas/filters/phone_number_filter.pydetects with a set of North-American Numbering Plan regex patterns (optional+1, strict 3-3-4). Numbers in other formats ship unredacted:+44 20 7946 0958,+33 1 42 68 53 00,+91 98765 43210,+49 30 901820, and national-format foreign numbers all fail the patterns.phonenumbersis not currently a dependency.This is the same fidelity gap that was found in the .NET runtime (its regex-only phone filter). The Java Phileas already avoids it: it detects via libphonenumber (
PhoneNumberUtil.findNumbers(input, "US", Leniency.POSSIBLE, ...)). The fix is to bring phileas-python to the same footing.Proposed change
phonenumbersas a dependency.phonenumbers.PhoneNumberMatcher(text, region, leniency=Leniency.POSSIBLE)(default region"US"), mirroring the Java filter:+-prefixed international numbers are found regardless of region, and bare national-format numbers are found for the default region.PhoneNumberMatcheris a scanner. Introduce a matcher-based phone filter rather than editing the pattern list. Retain the existing regex only if needed as a fallback for parity; otherwise remove it.Relationship to #48
This is the prerequisite for #48 (support the phone number filter
regionproperty). Once detection runs throughphonenumbers, #48 makes the default region configurable per policy (string or array). This issue closes the international-detection gap on its own, with the region still hardcoded to"US"(matching Java today).Acceptance criteria
phileas-pythondepends onphonenumbers.phonenumbers(default region"US", leniency comparable to libphonenumberPOSSIBLE).+44 20 7946 0958,+33 1 42 68 53 00,+91 98765 43210,+49 30 901820) are detected and redacted.(555) 123-4567,+1 555 123 4567,555-123-4567) - no regression.Unblocks #48.