# HG changeset patch # User Mads Kiilerich # Date 1508714106 -7200 # Node ID 5395bb85a991619aa46639c9c298b23d0b171c9e # Parent e6ce604d1ae041b3508d0d092726efa0c3755231 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 ' 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. diff -r e6ce604d1ae0 -r 5395bb85a991 kallithea/templates/changeset/diff_block.html --- 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 @@
${diff|n} - %if cs_filename.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']: + %if op and cs_filename.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']:
Show images
%if op == 'M': diff -r e6ce604d1ae0 -r 5395bb85a991 kallithea/tests/functional/test_files.py --- 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("""
Binary file
""") + + 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("""
Binary file
""")