Skip to content

Commit 06355db

Browse files
committed
Fixed space chars error in base decoding + hex lowercase error
1 parent 68b9aef commit 06355db

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

codext/base/_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def base_decode(input, charset, errors="strict", exc=BaseEncodeError):
113113
:param exc: exception to be raised in case of error
114114
"""
115115
i, n = 0, len(charset)
116+
input = re.sub(r"\s", "", input)
116117
for k, c in enumerate(input):
117118
try:
118119
i = i * n + charset.index(c)

codext/base/_base2n.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def base2n_decode(string, charset, errors="strict", exc=Base2NDecodeError):
7575
:param exc: exception to be raised in case of error
7676
"""
7777
bs, r, n = "", "", len(charset)
78+
# particular case: for hex, ensure the right case in the charset ; not that this way, if mixed cases are used, it
79+
# will trigger an error (this is the expected behavior)
80+
if n == 16:
81+
if any(c in string for c in "abcdef"):
82+
charset = charset.lower()
83+
elif any(c in string for c in "ABCDEF"):
84+
charset = charset.upper()
85+
string = re.sub(r"\s", "", string)
7886
# find the number of bits for the given character set and the number of
7987
# padding characters
8088
nb_in = int(log(n, 2))

0 commit comments

Comments
 (0)