misc: do not normalize form identifiers as phone numbers (#75073) #143

Merged
fpeters merged 1 commits from wip/75073-refine-fts-normalization into main 2023-03-03 08:47:57 +01:00
2 changed files with 18 additions and 1 deletions

View File

@ -4447,3 +4447,20 @@ def test_fts_phone(pub):
pub.site_options.add_section('options')
pub.site_options.set('options', 'default-country-code', 'BE')
assert formdef.data_class().count([FtsMatch('023456789')]) == 1
def test_fts_display_id(pub):
FormDef.wipe()
formdef = FormDef()
formdef.name = 'test'
formdef.fields = []
formdef.id = '123'
formdef.store()
formdata = formdef.data_class()()
formdata.data = {}
formdata.id = '4567'
formdata.just_created()
formdata.store()
assert formdef.data_class().count([FtsMatch('123-4567')]) == 1

View File

@ -440,7 +440,7 @@ class FtsMatch(Criteria):
self.value = self.get_fts_value(value)
if extra_normalize:
phone_match = re.match(r'.*?(?P<phone>\b\+?[-\(\)\d\.\s/]{6,20}\b)', self.value)
if phone_match:
if phone_match and not re.match(r'^\d+-\d+$', phone_match.group('phone').strip()):
# if it looks like a phone number, normalize it to its
# "international/E164" format to match what's stored in the
# database.