Skip to content

Find phone numbers with a bare 1 country code and an area code beginning with 1 - #117

Open
vamsibvv wants to merge 1 commit into
philterd:mainfrom
vamsibvv:phone-bare-country-code
Open

vamsibvv wants to merge 1 commit into
philterd:mainfrom
vamsibvv:phone-bare-country-code

Conversation

@vamsibvv

Copy link
Copy Markdown

Fixes #107.

Without a +, libphonenumber reads the leading 1 of 1-112-997-5633 as the country code and then the area code's 1 as a national prefix, which leaves nine digits, so the match is dropped. +1 112-997-5633 and 112-997-5633 were found.

As suggested in the issue (and as in philterd/phileas#458), when a configured region uses country code 1, the filter also scans, once, a copy of the text in which a bare 1 country code followed by a separator becomes +1. 1- and +1 have the same length, so offsets carry over. A match from the copy is kept only where the scan of the text found nothing overlapping, so Item 1 112-997-5633 still gives 112-997-5633 with the same confidence. Span text and confidence now come from text[match.start:match.end] rather than raw_string, which would be the rewritten copy.

Tests (TestBareCountryCode): 1-112-997-5633, 1 112 997 5633, 1.112.997.5633 and 1-109-299-5128 x512 give one span covering the whole number, with input offsets and text; a GB-only filter does not rewrite; Item 1 112-997-5633 and 1 (112) 997-5633 keep their spans and confidence; and +1 112-997-5633, 1-212-997-5633 (found) and 11129975633 (not found) are pinned. The five positive cases fail on main. The phone number section of docs/filters.md now describes the possible-number check, the +1 reading and the 11129975633 case, and there is a release note under Unreleased.

Full suite: 2403 passed, 2 skipped (without tests/test_ph_eye_filter_download_e2e.py).

AI assistance (Claude Code) was used for this change.

…ing with 1

Without a '+', libphonenumber strips the leading 1 as the country code
and then the area code's 1 as a national prefix, so 1-112-997-5633 was
missed while +1 112-997-5633 was found. When a configured region uses
country code 1, also scan a copy of the text in which a bare '1-' is
'+1', keeping a match from the copy only where the text had none. Same
as the Java library.

Fixes philterd#107.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phone numbers with a 1 country code and an area code beginning with 1 are not found

1 participant