aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Bertogli <albertito@blitiri.com.ar>2013-11-02 20:14:36 +0100
committerAlberto Bertogli <albertito@blitiri.com.ar>2013-11-02 20:14:36 +0100
commita42d7da6a4c33d12c0af1847ba4512b1a3f70287 (patch)
treef5a71d4e0da329a54d67dc8da108ece9ef44bc7f
parent21522f8a3a4a010ad717f5bdcbbc6584d9ba7527 (diff)
downloadgit-arr-fork-a42d7da6a4c33d12c0af1847ba4512b1a3f70287.zip
utils: Make the embedded image code use mimetypes
This patch makes minor changes to the code that handles embedded images, mostly to make it use mimetypes, and to remove SVG support (at least for now) due to security concerns. Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
-rw-r--r--utils.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/utils.py b/utils.py
index c7f63d0..b40624b 100644
--- a/utils.py
+++ b/utils.py
@@ -18,6 +18,7 @@ except ImportError:
markdown = None
import base64
+import mimetypes
def shorten(s, width = 60):
if len(s) < 60:
@@ -56,9 +57,8 @@ def can_markdown(fname):
def can_embed_image(fname):
"""True if we can embed image file in HTML, False otherwise."""
-
- exts = [ 'jpg', 'jpeg', 'png', 'gif', 'svg' ]
- if '.' in fname and fname.split('.')[-1] in exts:
+ exts = [ 'jpg', 'jpeg', 'png', 'gif' ]
+ if '.' in fname and fname.split('.')[-1].lower() in exts:
return True
return False
@@ -94,13 +94,7 @@ def markdown_blob(s):
return markdown.markdown(s)
def embed_image_blob(repo, dirname, fname):
- ext_to_mimetype = {'jpg': 'image/jpeg',
- 'jpeg': 'image/jpeg',
- 'png': 'image/png',
- 'gif': 'image/gif',
- 'svg': 'image/svg+xml',}
-
- mimetype = ext_to_mimetype[fname.split('.')[-1]]
+ mimetype = mimetypes.guess_type(fname)[0]
# Unfortunately, bottle seems to require utf-8 encoded data.
# We have to refetch the blob with raw=True, because the utf-8 encoded