From 48ff92e300696e2449070ac03b4916c76d4e77a3 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sun, 28 Apr 2019 23:35:42 +0200 Subject: Use an internal isdigits() function instead of str.isdigit() The problem with the latter is that it will also accept all kinds of unicode digits that are not the ASCII 0-9 digits causing all kinds of problems in check digit calculations. Some of these unicode characters are also considered digits by int() but some are not (such as the SUPERSCRIPT TWO unicode character). Closes https://github.com/arthurdejong/python-stdnum/issues/96 --- stdnum/ca/bn.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'stdnum/ca/bn.py') diff --git a/stdnum/ca/bn.py b/stdnum/ca/bn.py index d55f34a..0345d83 100644 --- a/stdnum/ca/bn.py +++ b/stdnum/ca/bn.py @@ -45,7 +45,7 @@ InvalidFormat: ... from stdnum import luhn from stdnum.exceptions import * -from stdnum.util import clean +from stdnum.util import clean, isdigits def compact(number): @@ -60,13 +60,13 @@ def validate(number): number = compact(number) if len(number) not in (9, 15): raise InvalidLength() - if not number[:9].isdigit(): + if not isdigits(number[:9]): raise InvalidFormat() luhn.validate(number[:9]) if len(number) == 15: if number[9:11] not in ('RC', 'RM', 'RP', 'RT'): raise InvalidComponent() - if not number[11:].isdigit(): + if not isdigits(number[11:]): raise InvalidFormat() return number -- cgit v1.2.3