added repair part
@@ -586,6 +586,7 @@ class pisaFileObject:
"""
def __init__(self, uri, basepath=None):
+
self.basepath = basepath
self.mimetype = None
self.file = None
@@ -602,8 +603,18 @@ class pisaFileObject:
if uri.startswith("data:"):
m = _rx_datauri.match(uri)
self.mimetype = m.group("mime")
- b64 = urllib_unquote(m.group("data")).encode("utf-8")
+
+ b64 = urllib_unquote(m.group("data"))
+
+ # The data may be incorrectly unescaped... repairs needed
+ b64 = b64.strip("b'").strip("'").encode()
+ b64 = re.sub(b"\\n", b'', b64)
+ b64 = re.sub(b'[^A-Za-z0-9\+\/]+', b'', b64)
+
+ # Add padding as needed, to make length into a multiple of 4
+ #
b64 += b"=" * ((4 - len(b64) % 4) % 4)
+
self.data = base64.b64decode(b64)
else:
