Skip to content

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

Merged
jzonthemtn merged 1 commit into
philterd:mainfrom
vamsibvv:phone-bare-country-code
Nov 12, 2026
Merged

jzonthemtn merged 1 commit into
philterd:mainfrom
vamsibvv:phone-bare-country-code

Conversation

@vamsibvv

Copy link
Copy Markdown
Contributor

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.

@vamsibvv
vamsibvv force-pushed the phone-bare-country-code branch from 159e784 to e2857f7 Compare November 11, 2026 06:55

@jzonthemtn jzonthemtn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vamsibvv Looks good - just the commit sign off (sorry again).

…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.

Signed-off-by: Vamsi <16957347+vamsibvv@users.noreply.github.com>
@vamsibvv
vamsibvv force-pushed the phone-bare-country-code branch from f2b0649 to 328d154 Compare November 11, 2026 17:31
@vamsibvv

Copy link
Copy Markdown
Contributor Author

Signed off now, thanks!

@jzonthemtn
jzonthemtn merged commit e24700f into philterd:main Nov 12, 2026
3 checks passed
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

2 participants