# HG changeset patch # User Mads Kiilerich # Date 2017-10-23 01:15:06 # 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 --git a/kallithea/templates/changeset/diff_block.html b/kallithea/templates/changeset/diff_block.html --- a/kallithea/templates/changeset/diff_block.html +++ b/kallithea/templates/changeset/diff_block.html @@ -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 --git a/kallithea/tests/functional/test_files.py b/kallithea/tests/functional/test_files.py --- a/kallithea/tests/functional/test_files.py +++ b/kallithea/tests/functional/test_files.py @@ -765,3 +765,19 @@ class TestFilesController(TestController '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
""")