mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-11 13:03:45 -05:00
Make robust the replacement of temp file paths with actual paths.
The previous implementation meant the temp file paths were treated as regular expressions, which was vulnerable to problems with backslashes etc. See #494.
This commit is contained in:
@@ -228,13 +228,28 @@ endfunction
|
||||
|
||||
" Replaces references to temp files with the actual file.
|
||||
function! s:fix_file_references(filepath, hunk_diff)
|
||||
let diff = a:hunk_diff
|
||||
for tmp in matchlist(diff, '\vdiff --git ./(\S+) ./(\S+)\n')[1:2]
|
||||
let diff = substitute(diff, tmp, a:filepath, 'g')
|
||||
endfor
|
||||
return diff
|
||||
let lines = split(a:hunk_diff, '\n')
|
||||
|
||||
let left_prefix = matchstr(lines[2], '[abciow12]').'/'
|
||||
let right_prefix = matchstr(lines[3], '[abciow12]').'/'
|
||||
let quote = lines[0][11] == '"' ? '"' : ''
|
||||
|
||||
let left_file = quote.left_prefix.a:filepath.quote
|
||||
let right_file = quote.right_prefix.a:filepath.quote
|
||||
|
||||
let lines[0] = 'diff --git '.left_file.' '.right_file
|
||||
let lines[2] = '--- '.left_file
|
||||
let lines[3] = '+++ '.right_file
|
||||
|
||||
return join(lines, "\n")."\n"
|
||||
endfunction
|
||||
|
||||
if $TEST
|
||||
function! gitgutter#hunk#fix_file_references(filepath, hunk_diff)
|
||||
return s:fix_file_references(a:filepath, a:hunk_diff)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
|
||||
function! s:adjust_hunk_summary(hunk_diff) abort
|
||||
let line_adjustment = s:line_adjustment_for_current_hunk()
|
||||
|
||||
Reference in New Issue
Block a user