Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdnum/ad/nrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def validate(number: str) -> str:
number = compact(number)
if len(number) != 8:
raise InvalidLength()
if not number[0].isalpha() or not number[-1].isalpha():
if not ('A' <= number[0] <= 'Z') or not ('A' <= number[-1] <= 'Z'):
raise InvalidFormat()
if not isdigits(number[1:-1]):
raise InvalidFormat()
Expand Down
2 changes: 1 addition & 1 deletion stdnum/br/cnpj.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@


# Minimal regex of valid characters
_cnpj_re = re.compile(r'^[\dA-Z]+$')
_cnpj_re = re.compile(r'^[0-9A-Z]+$')


def compact(number: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion stdnum/es/cae.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def validate(number: str) -> str:
raise InvalidFormat()
if not isdigits(number[9:12]):
raise InvalidFormat()
if not number[12].isalpha():
if not ('A' <= number[12] <= 'Z'):
raise InvalidFormat()
return number

Expand Down
7 changes: 6 additions & 1 deletion stdnum/eu/banknote.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@

from __future__ import annotations

import re

from stdnum.exceptions import *
from stdnum.util import clean, isdigits


_prefix_re = re.compile(r'^[0-9A-Z]{2}$')


def compact(number: str) -> str:
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
Expand All @@ -53,7 +58,7 @@ def checksum(number: str) -> int:
def validate(number: str) -> str:
"""Check if the number is a valid banknote serial number."""
number = compact(number)
if not number[:2].isalnum() or not isdigits(number[2:]):
if not _prefix_re.match(number[:2]) or not isdigits(number[2:]):
raise InvalidFormat()
if len(number) != 12:
raise InvalidLength()
Expand Down
4 changes: 2 additions & 2 deletions stdnum/fi/hetu.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
# Finnish personal identity codes are composed of date part, century
# indicating sign, individual number and control character.
# ddmmyyciiiC
_hetu_re = re.compile(r'^(?P<day>[0123]\d)(?P<month>[01]\d)(?P<year>\d\d)'
r'(?P<century>[-+ABCDEFYXWVU])(?P<individual>\d\d\d)'
_hetu_re = re.compile(r'^(?P<day>[0123][0-9])(?P<month>[01][0-9])(?P<year>[0-9][0-9])'
r'(?P<century>[-+ABCDEFYXWVU])(?P<individual>[0-9][0-9][0-9])'
r'(?P<control>[0-9ABCDEFHJKLMNPRSTUVWXY])$')


Expand Down
4 changes: 2 additions & 2 deletions stdnum/is_/kennitala.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
# organisations instead of birth date, the registration date is used,
# and number 4 is added to the first digit.
_kennitala_re = re.compile(
r'^(?P<day>[01234567]\d)(?P<month>[01]\d)(?P<year>\d\d)'
r'(?P<random>\d\d)(?P<control>\d)'
r'^(?P<day>[01234567][0-9])(?P<month>[01][0-9])(?P<year>[0-9][0-9])'
r'(?P<random>[0-9][0-9])(?P<control>[0-9])'
r'(?P<century>[09])$')


Expand Down
2 changes: 1 addition & 1 deletion stdnum/ro/onrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

# This pattern should match numbers that for some reason have a full date
# as last field for the old format
_old_onrc_fulldate_re = re.compile(r'^([A-Z][0-9]+/[0-9]+/)\d{2}[.]\d{2}[.](\d{4})$')
_old_onrc_fulldate_re = re.compile(r'^([A-Z][0-9]+/[0-9]+/)[0-9]{2}[.][0-9]{2}[.]([0-9]{4})$')

# This pattern should match all valid numbers in the old format
_old_onrc_re = re.compile(r'^[A-Z][0-9]+/[0-9]+/[0-9]+$')
Expand Down
2 changes: 1 addition & 1 deletion stdnum/si/maticna.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def validate(number: str) -> str:
raise InvalidLength()
if not isdigits(number[:6]):
raise InvalidFormat()
if not re.match(r'^([A-Za-z0-9]\d{2})?$', number[7:]):
if not re.match(r'^([A-Za-z0-9][0-9]{2})?$', number[7:]):
raise InvalidFormat()
if calc_check_digit(number) != number[6]:
raise InvalidChecksum()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_ad_nrt.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,9 @@ These have been found online and should all be valid numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not nrt.is_valid(x)]
[]


Non-ASCII digits and letters are not valid and should be rejected.

>>> nrt.is_valid('U-132950-\u00e9')
False
6 changes: 6 additions & 0 deletions tests/test_br_cnpj.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ These have been found online and should all be valid numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not cnpj.is_valid(x)]
[]


Non-ASCII digits and letters are not valid and should be rejected.

>>> cnpj.is_valid('07.195.358/000\u0661-66')
False
6 changes: 6 additions & 0 deletions tests/test_es_cae.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,9 @@ These should all be valid numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not cae.is_valid(x)]
[]


Non-ASCII digits and letters are not valid and should be rejected.

>>> cae.is_valid('ES00008V1488\u00e9')
False
6 changes: 6 additions & 0 deletions tests/test_eu_banknote.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ These should all be valid serial numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not banknote.is_valid(x)]
[]


Non-ASCII digits and letters are not valid and should be rejected.

>>> banknote.is_valid('P\u00e96007033744')
False
6 changes: 6 additions & 0 deletions tests/test_fi_hetu.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ compact() and format() don't do much special:
'131052A308T'
>>> hetu.format('131052a308t')
'131052A308T'


Non-ASCII digits and letters are not valid and should be rejected.

>>> hetu.is_valid('131052-30\u0668T')
False
6 changes: 6 additions & 0 deletions tests/test_is_kennitala.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ These have been found online and should all be valid numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not kennitala.is_valid(x)]
[]


Non-ASCII digits and letters are not valid and should be rejected.

>>> kennitala.is_valid('120174-33\u06699')
False
6 changes: 6 additions & 0 deletions tests/test_ro_onrc.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,9 @@ These have been found online and should all be valid numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not onrc.is_valid(x)]
[]


Non-ASCII digits and letters are not valid and should be rejected.

>>> onrc.is_valid('J1/384/13.0\u0663.2015')
False
6 changes: 6 additions & 0 deletions tests/test_si_maticna.doctest
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@ These have been found online and should all be valid numbers.
... '''
>>> [x for x in numbers.splitlines() if x and not maticna.is_valid(x)]
[]


Non-ASCII digits and letters are not valid and should be rejected.

>>> maticna.is_valid('187603101\u0663')
False
Loading