From 931d9056109b8fd9a84e8e0067fa46ca205ea1e2 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 27 Mar 2020 11:18:33 +0100 Subject: [PATCH] misc: accept / in phone numbers (#41082) --- src/authentic2/attribute_kinds.py | 2 +- tests/test_fields.py | 40 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/test_fields.py diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py index 09109b29..f8d9e6a7 100644 --- a/src/authentic2/attribute_kinds.py +++ b/src/authentic2/attribute_kinds.py @@ -120,7 +120,7 @@ class PhoneNumberField(forms.CharField): def clean(self, value): if value not in self.empty_values: - value = re.sub(r'[-.\s]', '', value) + value = re.sub(r'[-.\s/]', '', value) validate_phone_number(value) return value diff --git a/tests/test_fields.py b/tests/test_fields.py new file mode 100644 index 00000000..56c55d3b --- /dev/null +++ b/tests/test_fields.py @@ -0,0 +1,40 @@ +# authentic2 - versatile identity manager +# Copyright (C) 2010-2020 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from __future__ import unicode_literals + +import pytest + +from django.core.exceptions import ValidationError + +from authentic2.attribute_kinds import PhoneNumberField + + +def test_phonenumber_field(): + field = PhoneNumberField() + + # positive + for value in [ + '01 01 01 01 01', + '+01 01 01 01 01', + ' + 01/01.01-01.01', + '+01/01.01-01.01']: + field.clean(value) + + # negative + for value in ['01a01']: + with pytest.raises(ValidationError): + field.clean(value) -- 2.24.0