From 687f60e50d4e30188add078a9e329483e30e4aea Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 24 2017 09:45:05 +0000 Subject: [PATCH 1/2] To add a list to a list use extend() not append() --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 6615658..4b9a7b3 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3286,11 +3286,11 @@ def text2markdown(text, extended=True, readme=False): ] # Some extensions are disabled for READMEs and enabled otherwise if readme: - extensions.append( + extensions.extend([ 'markdown.extensions.abbr', 'markdown.extensions.footnotes', 'markdown.extensions.toc', - ) + ]) else: extensions.append( 'markdown.extensions.nl2br', From 1004568e3373b5b4de5ab790d94d3335fac68c3e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 24 2017 09:45:24 +0000 Subject: [PATCH 2/2] Fix rendering empty files The first if checks if we can encode the text, if we can then it's a file otherwise we treat it as binary. However, we were doing ``if file_content`` as the file_content variable is set when the encoding works. However, in the case of an empty file, we could encode it so we have a valid ``file_content`` variable which contains... an empty string. So it would fail the ``if file_content`` check. We fix this by simply changing the check to ``if file_content is not None`` then we're sure the encoding worked and we do not care if the content is an empty string or not. --- diff --git a/pagure/templates/file.html b/pagure/templates/file.html index 8fa38a1..c2c6595 100644 --- a/pagure/templates/file.html +++ b/pagure/templates/file.html @@ -159,14 +159,9 @@ {% endif %} {% if output_type=='file' %} - {% if content.size != 0 %} - {% autoescape false %} - {{ content | format_loc }} - {% endautoescape %} - {% else %} -

No content in the file

- {% endif %} - + {% autoescape false %} + {{ content | format_loc }} + {% endautoescape %} {% elif output_type == 'markup' %}
{% autoescape false %} diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 2c0e990..211614c 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -541,7 +541,7 @@ def view_file(repo, identifier, filename, username=None, namespace=None): # file and let the user download it instead of displaying # it. output_type = 'binary' - if file_content: + if file_content is not None: try: lexer = guess_lexer_for_filename( filename, @@ -565,7 +565,7 @@ def view_file(repo, identifier, filename, username=None, namespace=None): ) output_type = 'file' else: - output_type = 'file' + output_type = 'binary' else: output_type = 'binary' else: