0001-misc-only-allow-ascii-numbers-in-IBAN-and-other-chec.patch
tests/test_widgets.py | ||
---|---|---|
828 | 828 |
'FR76 2004 1000 0101 2345 6%02 068', |
829 | 829 |
'FR76 hello 234 6789 1234 6789 123', |
830 | 830 |
'FRxx 2004 1000 0101 2345 6Z02 068', |
831 |
'FR76 3000 6000 011² 3456 7890 189', # ² |
|
831 | 832 |
]: |
832 | 833 |
widget = WcsExtraStringWidget('test', value='foo', required=False) |
833 | 834 |
widget.field = fakefield |
wcs/qommon/misc.py | ||
---|---|---|
701 | 701 |
return True |
702 | 702 | |
703 | 703 | |
704 |
def is_ascii_digit(string_value): |
|
705 |
return string_value and all((x in '0123456789' for x in string_value)) |
|
706 | ||
707 | ||
704 | 708 |
def validate_siren(string_value): |
705 | 709 |
return validate_luhn(string_value, length=9) |
706 | 710 | |
707 | 711 | |
708 | 712 |
def validate_siret(string_value): |
709 | 713 |
# special case : La Poste |
710 |
if not string_value.isdigit():
|
|
714 |
if not is_ascii_digit(string_value):
|
|
711 | 715 |
return False |
712 | 716 |
if (string_value.startswith('356000000') |
713 | 717 |
and len(string_value) == 14 |
... | ... | |
733 | 737 |
string_value = string_value.replace('2A', '19', 1) |
734 | 738 |
elif dept == '2B': |
735 | 739 |
string_value = string_value.replace('2B', '18', 1) |
736 |
if not string_value.isdigit():
|
|
740 |
if not is_ascii_digit(string_value):
|
|
737 | 741 |
return False |
738 | 742 |
month = int(string_value[3:5]) |
739 | 743 |
if month < 50 and month not in list(range(1, 13)) + [20] + list(range(30, 43)): |
... | ... | |
751 | 755 |
bban = string_value[4:] |
752 | 756 |
if not (country_code.isalpha() and country_code.isupper()): |
753 | 757 |
return False |
754 |
if not iban_key.isdigit():
|
|
758 |
if not is_ascii_digit(iban_key):
|
|
755 | 759 |
return False |
756 | 760 |
dummy_iban = bban + country_code + '00' |
757 | 761 |
dummy_iban_converted = '' |
... | ... | |
760 | 764 |
dummy_iban_converted += str(ord(car) - ord('A') + 10) |
761 | 765 |
else: |
762 | 766 |
dummy_iban_converted += car |
763 |
if not dummy_iban_converted.isdigit():
|
|
767 |
if not is_ascii_digit(dummy_iban_converted):
|
|
764 | 768 |
return False |
765 | 769 |
return int(iban_key) == 98 - int(dummy_iban_converted) % 97 |
766 |
- |