mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 19:07:58 +00:00
Merge pull request #3862 from mtmail/skip-all-zero-postcodes
Postcode sanetizer now skips values which are only zeros
This commit is contained in:
@@ -29,6 +29,9 @@ class CountryPostcodeMatcher:
|
||||
self.norm_pattern = re.compile(f'\\s*(?:{country_code.upper()}[ -]?)?({pc_pattern})\\s*')
|
||||
self.pattern = re.compile(pc_pattern)
|
||||
|
||||
# We want to exclude 0000, 00-000, 000 00 etc
|
||||
self.zero_pattern = re.compile(r'^[0\- ]+$')
|
||||
|
||||
self.output = config.get('output', r'\g<0>')
|
||||
|
||||
def match(self, postcode: str) -> Optional[Match[str]]:
|
||||
@@ -40,7 +43,10 @@ class CountryPostcodeMatcher:
|
||||
normalized = self.norm_pattern.fullmatch(postcode.upper())
|
||||
|
||||
if normalized:
|
||||
return self.pattern.fullmatch(normalized.group(1))
|
||||
match = self.pattern.fullmatch(normalized.group(1))
|
||||
if match and self.zero_pattern.match(match.string):
|
||||
return None
|
||||
return match
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@@ -237,3 +237,9 @@ def test_postcode_default_pattern_pass(sanitize, postcode):
|
||||
@pytest.mark.sanitizer_params(convert_to_address=False, default_pattern='[A-Z0-9- ]{3,12}')
|
||||
def test_postcode_default_pattern_fail(sanitize, postcode):
|
||||
assert sanitize(country='an', postcode=postcode) == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("postcode", ('00000', '00-000', 'PL-00000', 'PL 00-000'))
|
||||
@pytest.mark.sanitizer_params(convert_to_address=False)
|
||||
def test_postcode_zeros(sanitize, postcode):
|
||||
assert sanitize(country='pl', postcode=postcode) == []
|
||||
|
||||
Reference in New Issue
Block a user