Skip to content

Commit

Permalink
Escape special characters in paths (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstanberry authored Apr 15, 2023
1 parent ff3a966 commit 2755788
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lua/zk/root_pattern_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ local M = {}
M.path = (function()
local is_windows = uv.os_uname().version:match("Windows")

local function escape_wildcards(path)
return path:gsub("([%[%]%?%*])", "\\%1")
end

local function exists(filename)
local stat = uv.fs_stat(filename)
return stat and stat.type or false
Expand Down Expand Up @@ -63,6 +67,7 @@ M.path = (function()
end

return {
escape_wildcards = escape_wildcards,
exists = exists,
join = path_join,
iterate_parents = iterate_parents,
Expand Down Expand Up @@ -92,7 +97,7 @@ function M.root_pattern(...)
local patterns = vim.tbl_flatten({ ... })
local function matcher(path)
for _, pattern in ipairs(patterns) do
for _, p in ipairs(vim.fn.glob(M.path.join(path, pattern), true, true)) do
for _, p in ipairs(vim.fn.glob(M.path.join(M.path.escape_wildcards(path), pattern), true, true)) do
if M.path.exists(p) then
return path
end
Expand Down

0 comments on commit 2755788

Please sign in to comment.