Skip to content

Commit 3405ad7

Browse files
committed
Handle edge case in common prefix calculation
1 parent ccd4972 commit 3405ad7

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

autoload/gitgutter/diff_highlight.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ endif
162162
"
163163
function! s:common_prefix(a, b)
164164
let len = min([len(a:a), len(a:b)])
165+
if len == 0
166+
return -1
167+
endif
165168
for i in range(len)
166169
if a:a[i:i] != a:b[i:i]
167170
return i - 1

test/test_gitgutter.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,9 @@ endfunction
916916

917917

918918
function Test_common_prefix()
919+
" zero length
920+
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('', 'foo'))
921+
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('foo', ''))
919922
" nothing in common
920923
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('-abcde', '+pqrst'))
921924
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('abcde', 'pqrst'))

0 commit comments

Comments
 (0)