From 3d16de197c7610a3e0701a3982a99e2fb5bd0e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A6var=20=C3=96fj=C3=B6r=C3=B0=20Magn=C3=BAsson?= Date: Thu, 12 Oct 2023 10:12:55 +0000 Subject: [PATCH 1/2] Set a boundary for the regular expression pattern If the boundary is not set, a user can enter a longer kennitala, and just as long as the check digit is at the right location from the end of the string, the kennitala is valid. --- kennitala/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kennitala/__init__.py b/kennitala/__init__.py index 34a61e9..5f9afd4 100644 --- a/kennitala/__init__.py +++ b/kennitala/__init__.py @@ -127,7 +127,7 @@ def validate(self): if not self.kennitala: return False - pattern = r'\d{6}\-?\d{4}' + pattern = r'\d{6}\-?\d{4}\b' if not re.match(pattern, self.kennitala): return False From 663b27ae568d4f935140cf8924c4ef1360fd3f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A6var=20=C3=96fj=C3=B6r=C3=B0=20Magn=C3=BAsson?= Date: Thu, 12 Oct 2023 12:53:46 +0000 Subject: [PATCH 2/2] Add a test case for invalid kennitalas --- tests/test_kennitala.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_kennitala.py b/tests/test_kennitala.py index 8194d14..8331887 100644 --- a/tests/test_kennitala.py +++ b/tests/test_kennitala.py @@ -21,6 +21,7 @@ '0503760647', '550376', '1405433219', + '28129420229', )