lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.13-2-ge513888

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.13-2-ge513888



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  e513888762af9c0d5fd698810e124cb9b5a47a92 (commit)
      from  77a77ba75706f8ebae5c5ef87146944ce5322c88 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=e513888762af9c0d5fd698810e124cb9b5a47a92

commit e513888762af9c0d5fd698810e124cb9b5a47a92
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Wed Feb 12 20:05:06 2020 +0100

    Fix issue with extra plus or minus in se.personnummer
    
    Fixes 5441ffa
    Closes https://github.com/arthurdejong/python-stdnum/issues/188

diff --git a/stdnum/se/personnummer.py b/stdnum/se/personnummer.py
index a495242..95d6180 100644
--- a/stdnum/se/personnummer.py
+++ b/stdnum/se/personnummer.py
@@ -2,7 +2,7 @@
 # coding: utf-8
 #
 # Copyright (C) 2018 Ilya Vihtinsky
-# Copyright (C) 2018 Arthur de Jong
+# Copyright (C) 2018-2020 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -32,8 +32,6 @@ More information:
 
 >>> validate('880320-0016')
 '880320-0016'
->>> validate('8803200016')
-'880320-0016'
 >>> validate('880320-0018')
 Traceback (most recent call last):
     ...
@@ -59,7 +57,7 @@ def compact(number):
     number = clean(number, ' :')
     if len(number) in (10, 12) and number[-5] not in '-+':
         number = '%s-%s' % (number[:-4], number[-4:])
-    return number
+    return number[:-5].replace('-', '').replace('+', '') + number[-5:]
 
 
 def get_birth_date(number):
@@ -102,10 +100,8 @@ def validate(number):
     number = compact(number)
     if len(number) not in (11, 13):
         raise InvalidLength()
-    if number[-5] not in '-+':
-        raise InvalidFormat()
-    digits = clean(number, '-+')
-    if not isdigits(digits):
+    digits = number[:-5] + number[-4:]
+    if number[-5] not in '-+' or not isdigits(digits):
         raise InvalidFormat()
     get_birth_date(number)
     luhn.validate(digits[-10:])
diff --git a/tests/test_se_personnummer.doctest 
b/tests/test_se_personnummer.doctest
index 2238e63..6c49322 100644
--- a/tests/test_se_personnummer.doctest
+++ b/tests/test_se_personnummer.doctest
@@ -1,7 +1,7 @@
 test_se_personnummer.doctest - more detailed doctests for 
stdnum.se.personnummer module
 
 Copyright (C) 2018 Ilya Vihtinsky
-Copyright (C) 2018 Arthur de Jong
+Copyright (C) 2018-2020 Arthur de Jong
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
@@ -26,8 +26,16 @@ is not really useful as module documentation.
 >>> from stdnum.se import personnummer
 
 
-Test for non-digit number.
+Test for various formats and corner cases.
 
+>>> personnummer.validate('8803200016')
+'880320-0016'
+>>> personnummer.validate('19670-19-9535')
+Traceback (most recent call last):
+    ...
+InvalidLength: ...
+>>> personnummer.validate('8803-20-0016')
+'880320-0016'
 >>> personnummer.validate('a' * 10)
 Traceback (most recent call last):
     ...

-----------------------------------------------------------------------

Summary of changes:
 stdnum/se/personnummer.py          | 12 ++++--------
 tests/test_se_personnummer.doctest | 12 ++++++++++--
 2 files changed, 14 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
python-stdnum