fix: do not pass sanitized directories into utils.dirs_match (#148)
parent
b0de69da63
commit
03990e44c3
|
|
@ -12,23 +12,18 @@ function M.fire(event)
|
|||
vim.api.nvim_exec_autocmds("User", { pattern = "Persisted" .. event })
|
||||
end
|
||||
|
||||
---Get the current working directory
|
||||
---@return string
|
||||
function M.cwd()
|
||||
return utils.sanitize_dir(vim.fn.getcwd())
|
||||
end
|
||||
|
||||
---Get the current session for the current working directory and git branch
|
||||
---@param opts? {branch?: boolean}
|
||||
---@return string
|
||||
function M.current(opts)
|
||||
opts = opts or {}
|
||||
local name = M.cwd()
|
||||
local name = utils.make_fs_safe(vim.fn.getcwd())
|
||||
|
||||
if config.use_git_branch and opts.branch ~= false then
|
||||
local branch = M.branch()
|
||||
if branch then
|
||||
name = name .. "@@" .. branch:gsub("[\\/:]+", "%%")
|
||||
branch = utils.make_fs_safe(branch)
|
||||
name = name .. "@@" .. branch
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -164,7 +159,7 @@ function M.allowed_dir(opts)
|
|||
end
|
||||
|
||||
opts = opts or {}
|
||||
local dir = opts.dir or M.cwd()
|
||||
local dir = opts.dir or vim.fn.getcwd()
|
||||
|
||||
return utils.dirs_match(dir, config.allowed_dirs) and not utils.dirs_match(dir, config.ignored_dirs)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
local M = {}
|
||||
|
||||
--- Escape special pattern matching characters in a string
|
||||
---@param dir string
|
||||
function M.sanitize_dir(dir)
|
||||
return dir:gsub("[\\/:]+", "%%")
|
||||
--- Escapes the given text to be safe for use in file-system paths/names,
|
||||
--- accounting for cross-platform use.
|
||||
---@param text string
|
||||
function M.make_fs_safe(text)
|
||||
return text:gsub("[\\/:]+", "%%")
|
||||
end
|
||||
|
||||
---Get the directory pattern based on OS
|
||||
|
|
@ -29,17 +30,17 @@ end
|
|||
---@param dirs table The table of directories to search in
|
||||
---@return boolean
|
||||
function M.dirs_match(dir, dirs)
|
||||
dir = M.sanitize_dir(vim.fn.expand(dir))
|
||||
dir = M.make_fs_safe(vim.fn.expand(dir))
|
||||
|
||||
for _, search in ipairs(dirs) do
|
||||
if type(search) == "string" then
|
||||
search = M.sanitize_dir(vim.fn.expand(search))
|
||||
search = M.make_fs_safe(vim.fn.expand(search))
|
||||
if M.is_subdirectory(search, dir) then
|
||||
return true
|
||||
end
|
||||
elseif type(search) == "table" then
|
||||
if search.exact then
|
||||
search = M.sanitize_dir(vim.fn.expand(search[1]))
|
||||
search = M.make_fs_safe(vim.fn.expand(search[1]))
|
||||
if dir == search then
|
||||
return true
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue