From 1004568e3373b5b4de5ab790d94d3335fac68c3e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 24 2017 09:45:24 +0000 Subject: 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: