Ver Fonte

decode data uri properly

Pi há 4 meses atrás
pai
commit
816c16ff85
1 ficheiros alterados com 7 adições e 1 exclusões
  1. 7 1
      rest/pyapi.py

+ 7 - 1
rest/pyapi.py

@@ -13,6 +13,7 @@ from bottle import (
     template, static_file,
     HTTPResponse,
 )
+from itertools import chain
 from base64 import urlsafe_b64decode as b64decode
 from linkpreview import link_preview
 
@@ -101,7 +102,12 @@ LIMIT 1;
         con.close()
 
     # extract bytes from data url
-    content = content.split(';')[-1]
+    _, mime, encoding, content = chain.from_iterable(map(
+        lambda x: x.split(','), chain.from_iterable(map(
+            lambda x: x.split(';'), content.split(':')
+        ))
+    ))
+    assert encoding == 'base64', f'unsupported encoding: {encoding}'
     content = b64decode(content + '==')
 
     if request.params.download == "false":