From 5d979d292612e082fee17adfdf779fd5227959fc Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 20 2015 13:49:58 +0000 Subject: Fix the encoding of the files we're displaying on the UI --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 1b66849..c2f15a6 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -393,7 +393,7 @@ def view_file(repo, identifier, filename, username=None): flask.abort(404, 'File not found') if isinstance(content, pygit2.Blob): - if content.is_binary or not pagure.lib.could_be_text(content.data): + if content.is_binary and not pagure.lib.could_be_text(content.data): ext = filename[filename.rfind('.'):] if ext in ( '.gif', '.png', '.bmp', '.tif', '.tiff', '.jpg', @@ -409,16 +409,17 @@ def view_file(repo, identifier, filename, username=None): else: output_type = 'binary' else: + file_content = content.data.decode('utf-8') try: lexer = guess_lexer_for_filename( filename, - content.data + file_content ) except (ClassNotFound, TypeError): lexer = TextLexer() content = highlight( - content.data, + file_content, lexer, HtmlFormatter( noclasses=True,