finder: fix root path trim (#1190)

Handle special characters and convert root path string to pattern string by escaping special characters with "%"
This commit is contained in:
Kairzhan 2023-07-19 13:30:58 +02:00 committed by GitHub
parent 3d98088411
commit 20eef6d607
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View file

@ -26,7 +26,7 @@ end
function M.path_sub(fname, root)
root = (root and fname:sub(1, #root) == root) and root or vim.env.HOME
root = root:sub(#root - #M.path_sep + 1) == M.path_sep and root or root .. M.path_sep
return fname:sub(#root + 1)
return fname:gsub(vim.pesc(root), '')
end
--get icon hlgroup color

View file

@ -70,5 +70,8 @@ describe('lspsaga util', function()
root = '/Users/test/workspace/vue-project'
res = util.path_sub('/Users/test/workspace/vue-project/src/main.vue', root)
assert.is_equal('src/main.vue', res)
root = '/Users/test/(test-dir)/%proj-rs/'
res = util.path_sub('/Users/test/(test-dir)/%proj-rs/src/main.rs', root)
assert.is_equal('src/main.rs', res)
end)
end)