From 67ef116100b40f9ca128196504a2e0bc0a2753b0 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Fri, 5 Jan 2024 12:43:02 +0000 Subject: [PATCH] Fix the fix for colons in basepath Commit 84bc2d6 tried to handle basepath values where the path contained colons (see #877). However the fix had two (!) bugs. - It used strridx() to find the colon separating the diffbase and the path; it should have used stridx() because the base comes first. - It used substring indexes incorrectly: foo[0:-1] returns the whole of foo, not an empty string (:help exr-[:]). Closes #878. --- autoload/gitgutter/utility.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index 162f547..9c2b9c3 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -252,8 +252,14 @@ function! gitgutter#utility#base_path(bufnr) " If we already know the original path at this diff base, return it. let basepath = gitgutter#utility#getbufvar(a:bufnr, 'basepath', '') if !empty(basepath) - let i = strridx(basepath, ':') - let [base, bpath] = [basepath[0:i-1], basepath[i+1:]] + " basepath is diffbase:path + " Note that path can also contain colons. + " List destructuring / unpacking where the remaining items are assigned + " to a single variable (:help let-unpack) is only available in v8.2.0540. + let parts = split(basepath, ':', 1) + let base = parts[0] + let bpath = join(parts[1:], ':') + if base == diffbase return gitgutter#utility#shellescape(bpath) endif