forked from GithubBackups/healthchecks
Improve phone number sanitization: remove spaces and hyphens
This commit is contained in:
parent
81e59ac553
commit
f7e004b2ea
@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
|
||||
- Update the read-only dashboard's CSS for better mobile support (#442)
|
||||
- Reduce the number of SQL queries used in the "Get Checks" API call
|
||||
- Add support for script's exit status in ping URLs (#429)
|
||||
- Improve phone number sanitization: remove spaces and hyphens
|
||||
|
||||
## v1.17.0 - 2020-10-14
|
||||
|
||||
|
@ -204,6 +204,7 @@ class AddSmsForm(forms.Form):
|
||||
v = self.cleaned_data["value"]
|
||||
|
||||
stripped = v.encode("ascii", "ignore").decode("ascii")
|
||||
stripped = stripped.replace(" ", "").replace("-", "")
|
||||
if not re.match(r"^\+\d{5,15}$", stripped):
|
||||
raise forms.ValidationError("Invalid phone number format.")
|
||||
|
||||
|
@ -75,3 +75,23 @@ class AddSmsTestCase(BaseTestCase):
|
||||
|
||||
c = Channel.objects.get()
|
||||
self.assertEqual(c.phone_number, "+1234567890")
|
||||
|
||||
def test_it_strips_hyphens(self):
|
||||
form = {"label": "My Phone", "value": "+123-4567890"}
|
||||
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.post(self.url, form)
|
||||
self.assertRedirects(r, self.channels_url)
|
||||
|
||||
c = Channel.objects.get()
|
||||
self.assertEqual(c.phone_number, "+1234567890")
|
||||
|
||||
def test_it_strips_spaces(self):
|
||||
form = {"label": "My Phone", "value": "+123 45 678 90"}
|
||||
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.post(self.url, form)
|
||||
self.assertRedirects(r, self.channels_url)
|
||||
|
||||
c = Channel.objects.get()
|
||||
self.assertEqual(c.phone_number, "+1234567890")
|
||||
|
Loading…
x
Reference in New Issue
Block a user