From 468f7a98afc42b74401b03136e26f7134e8586b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Larra=C3=ADn?= Date: Wed, 15 May 2019 11:58:57 -0400 Subject: [PATCH] libs.encoding_utils: improve `clean_base64` --- cl_sii/libs/encoding_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cl_sii/libs/encoding_utils.py b/cl_sii/libs/encoding_utils.py index 9a6adb14..fbfa1897 100644 --- a/cl_sii/libs/encoding_utils.py +++ b/cl_sii/libs/encoding_utils.py @@ -24,7 +24,13 @@ def clean_base64(value: Union[str, bytes]) -> bytes: raise TypeError("Value must be str or bytes.") # remove line breaks and spaces - value_base64_bytes_cleaned = value_base64_bytes.replace(b'\n', b'').replace(b' ', b'') + # warning: we may only remove characters that are not part of the standard base-64 alphabet + # (or any of its popular alternatives). + value_base64_bytes_cleaned = value_base64_bytes \ + .replace(b'\n', b'') \ + .replace(b'\r', b'') \ + .replace(b'\t', b'') \ + .replace(b' ', b'') return value_base64_bytes_cleaned