Mercurial > kallithea
changeset 6949:5395bb85a991
diff: fix crash when displaying diff on a single file
File diff on an image file would fail on
%if op in 'DM':
because op was None:
TypeError: 'in <string>' requires string as left operand, not NoneType
But really, if op is None, we also don't want to show invalid "Show images"
links. Thus, guard the whole image display section with having an actual op.
_parse_gitdiff will never return op None, but wrapped_diff is more lazy and
might do that. It could be considered a bug in wrapped_diff, and this change is
just a bad workaround.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Mon, 23 Oct 2017 01:15:06 +0200 |
parents | e6ce604d1ae0 |
children | 89e1117dbfbb |
files | kallithea/templates/changeset/diff_block.html kallithea/tests/functional/test_files.py |
diffstat | 2 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/templates/changeset/diff_block.html Sun Oct 22 23:00:37 2017 +0200 +++ b/kallithea/templates/changeset/diff_block.html Mon Oct 23 01:15:06 2017 +0200 @@ -75,7 +75,7 @@ </div> <div class="no-padding panel-body" data-f_path="${h.safe_unicode(cs_filename)}"> ${diff|n} - %if cs_filename.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']: + %if op and cs_filename.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']: <div class="btn btn-image-diff-show">Show images</div> %if op == 'M': <div id="${id_fid}_image-diff" class="btn btn-image-diff-swap" style="display:none">Press to swap images</div>
--- a/kallithea/tests/functional/test_files.py Sun Oct 22 23:00:37 2017 +0200 +++ b/kallithea/tests/functional/test_files.py Mon Oct 23 01:15:06 2017 +0200 @@ -765,3 +765,19 @@ 'Successfully deleted file %s' % posixpath.join(location, filename)) finally: fixture.destroy_repo(repo.repo_name) + + def test_png_diff_no_crash_hg(self): + self.log_user() + response = self.app.get(url('files_diff_home', + repo_name=HG_REPO, + f_path='docs/theme/ADC/static/documentation.png', + diff1='tip', diff2='tip')) + response.mustcontain("""<pre>Binary file</pre>""") + + def test_png_diff_no_crash_git(self): + self.log_user() + response = self.app.get(url('files_diff_home', + repo_name=GIT_REPO, + f_path='docs/theme/ADC/static/documentation.png', + diff1='master', diff2='master')) + response.mustcontain("""<pre>Binary file</pre>""")