From da7798568f54c1ff9443fefcdf7c720074d79754 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 01 2017 21:30:19 +0000 Subject: Fix displaying binary files in the documentation This was caused by a change to __get_tree_and_content which tries to convert the file and for this tries to guess the encoding. Of course for binary files (such as images) this fails and we were ending up with a 500 error. With this change, we first check if the file is a binary and if it is we just display it as such without trying to convert it. --- diff --git a/pagure/docs_server.py b/pagure/docs_server.py index 172028d..c9b7ff7 100644 --- a/pagure/docs_server.py +++ b/pagure/docs_server.py @@ -14,6 +14,8 @@ import os import flask import pygit2 +from binaryornot.helpers import is_binary_string + import pagure.doc_utils import pagure.exceptions import pagure.lib @@ -108,7 +110,11 @@ def __get_tree_and_content(repo_obj, commit, path): if isinstance(blob_or_tree, pygit2.TreeEntry): # Returned a file ext = os.path.splitext(blob_or_tree.name)[1] blob_obj = repo_obj[blob_or_tree.oid] - content, safe = pagure.doc_utils.convert_readme(blob_obj.data, ext) + if not is_binary_string(blob_obj.data): + content, safe = pagure.doc_utils.convert_readme(blob_obj.data, ext) + else: + safe = True + content = blob_obj.data tree = sorted(tree_obj, key=lambda x: x.filemode) return (tree, content, safe, extended)