sql: do not consider numbers not starting with 0 as phone numbers (#75594)
gitea/wcs/pipeline/head Build queued... Details

This commit is contained in:
Frédéric Péters 2023-03-20 16:16:47 +01:00 committed by Gitea
parent e682f42fb4
commit 00222aae84
2 changed files with 9 additions and 2 deletions

View File

@ -4442,7 +4442,7 @@ def test_fts_phone(pub):
assert formdef.data_class().count([FtsMatch('+33(0)123456789 bar')]) == 0
assert formdef.data_class().count([FtsMatch('foo +33(0)123456789')]) == 1
assert formdef.data_class().count([FtsMatch('bar +33(0)123456789')]) == 0
assert formdef.data_class().count([FtsMatch('123456789')]) == 2
assert formdef.data_class().count([FtsMatch('123456789')]) == 1
formdata.data = {'1': '+32 2 345 67 89', '2': 'foo'}
formdata.store()

View File

@ -440,7 +440,14 @@ class FtsMatch(Criteria):
self.attribute = 'fts'
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)
phone_match = re.match(
r'''.*?(?P<phone> # a phone number
((\+[1-9])|(\b0)) # starting with an international prefix, or 0
[-\(\)\d\.\s/]{6,20} # then a bunch of numbers/symbols
\b) # till the end of the "word"''',
self.value,
re.X,
)
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