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:
parent
3d98088411
commit
20eef6d607
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue