From b0235c425856571409c7de4c5d0dc21538d2ee62 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 19 2015 10:06:06 +0000 Subject: [PATCH 1/2] Let's decode the string received instead of encoding it This should make more sense, we may have retrieved bytes from pygit2, thus we try to decode it and find out if it is a text file or not --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 385ff16..76b7e60 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2440,7 +2440,7 @@ def could_be_text(text): """ Returns wether we think this chain of character could be text or not """ try: - text.encode('utf-8') + text.decode('utf-8') return True except: return False From ed14c30b2b90429dbf63fdd0f56d2318f4f1eaab Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 22 2015 11:09:46 +0000 Subject: [PATCH 2/2] More decoding to UTF-8 to handle READMEs --- diff --git a/pagure/doc_utils.py b/pagure/doc_utils.py index d2c5b58..a707d36 100644 --- a/pagure/doc_utils.py +++ b/pagure/doc_utils.py @@ -97,9 +97,9 @@ def convert_readme(content, ext, view_file_url=None): safe = False if ext and ext in ['.rst']: safe = True - output = convert_doc(content, view_file_url) + output = convert_doc(content.decode('utf-8'), view_file_url) elif ext and ext in ['.mk', '.md']: - output = markdown.markdown(content) + output = markdown.markdown(content.decode('utf-8')) safe = True elif not ext or (ext and ext in ['.text', '.txt']): safe = True