Skip to content

fix(analyzer): use valid region code GB instead of UK in PhoneRecognizer#2174

Open
developer0hye wants to merge 1 commit into
data-privacy-stack:mainfrom
developer0hye:fix/phone-recognizer-uk-region-gb
Open

fix(analyzer): use valid region code GB instead of UK in PhoneRecognizer#2174
developer0hye wants to merge 1 commit into
data-privacy-stack:mainfrom
developer0hye:fix/phone-recognizer-uk-region-gb

Conversation

@developer0hye

Copy link
Copy Markdown

Change Description

Fixes #2173.

PhoneRecognizer.DEFAULT_SUPPORTED_REGIONS contained "UK", which is not a valid region code in the phonenumbers library (Google libphonenumber). Region codes are ISO 3166-1 alpha-2, where the United Kingdom is "GB".

Because "UK" is not a real region, that entry was a no-op, and UK numbers in national/local format were never detected with the default configuration. Only international-format +44 … numbers matched — those carry the country code and match under any region, which is why the gap went unnoticed (the existing +44 (20) 7123 4567 test passes for exactly this reason).

>>> import phonenumbers
>>> "UK" in phonenumbers.SUPPORTED_REGIONS
False
>>> phonenumbers.country_code_for_region("UK")
0
>>> phonenumbers.country_code_for_region("GB")
44

Detection of a national-format UK number, before vs. after:

text before ("UK") after ("GB")
020 7946 0958 (London landline) not detected ❌ detected ✅
07911 123456 (mobile) not detected ❌ detected ✅
+44 7911 123456 (international) detected ✅ detected ✅

Changes

  • phone_recognizer.py: replace "UK" with "GB" in DEFAULT_SUPPORTED_REGIONS.
  • test_phone_recognizer.py: add a regression test for a national-format UK number (020 7946 0958).
  • CHANGELOG.md: document the fix under [unreleased] → Analyzer → Fixed.

How Has This Been Tested?

  • pytest tests/test_phone_recognizer.py — 27 passed (including the new case).
  • ruff check presidio-analyzer/presidio_analyzer — all checks passed.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (CHANGELOG)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

…ognizer

`PhoneRecognizer.DEFAULT_SUPPORTED_REGIONS` contained "UK", which is not a
valid region code in the phonenumbers library (Google libphonenumber). Region
codes are ISO 3166-1 alpha-2, where the United Kingdom is "GB"
(country_code_for_region("UK") == 0, and "UK" is not in
phonenumbers.SUPPORTED_REGIONS).

As a result the "UK" entry was a no-op: UK numbers written in national/local
format (e.g. "020 7946 0958") were never detected with the default
configuration. Only international-format "+44 ..." numbers matched, because
they carry the country code and match under any region.

Replaced "UK" with "GB" and added a regression test for a national-format
UK number.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a correctness gap in Presidio Analyzer’s PhoneRecognizer default configuration by switching the invalid libphonenumber region code "UK" to the valid ISO 3166-1 alpha-2 code "GB", restoring detection of UK national-format phone numbers under default settings.

Changes:

  • Updated PhoneRecognizer.DEFAULT_SUPPORTED_REGIONS from "UK" to "GB".
  • Added a regression test ensuring a UK national-format number (020 7946 0958) is detected with defaults.
  • Documented the fix in the Analyzer “Fixed” section of CHANGELOG.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
presidio-analyzer/presidio_analyzer/predefined_recognizers/generic/phone_recognizer.py Replaces invalid default region "UK" with valid "GB" to enable UK national-format matching.
presidio-analyzer/tests/test_phone_recognizer.py Adds a regression case proving UK national-format numbers are detected with the corrected default regions.
CHANGELOG.md Records the behavior change/fix under [unreleased] → Analyzer → Fixed.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PhoneRecognizer: "UK" in DEFAULT_SUPPORTED_REGIONS is not a valid libphonenumber region (UK national-format numbers undetected)

2 participants