Changeset - 5395bb85a991
[Not reviewed]
default
0 2 0
Mads Kiilerich - 8 years ago 2017-10-23 01:15:06
mads@kiilerich.com
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.
2 files changed with 17 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/templates/changeset/diff_block.html
Show inline comments
 
@@ -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>
kallithea/tests/functional/test_files.py
Show inline comments
 
@@ -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("""<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>""")
0 comments (0 inline, 0 general)