aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2022-05-02 11:01:51 -0400
committerGitHub <noreply@github.com>2022-05-02 11:01:51 -0400
commita1542b091dd7b919fa8524c1c909ef897dde9299 (patch)
treedfa2394fcc39ede5ab5c0d51f9b4abbe5b012048 /runtime/lua/vim
parentaf53fa06636586511a6208094332d2e1245ab2a0 (diff)
parent88595fbb212c0b770ed6aa08b09561af608c73e0 (diff)
downloadrneovim-a1542b091dd7b919fa8524c1c909ef897dde9299.tar.gz
rneovim-a1542b091dd7b919fa8524c1c909ef897dde9299.tar.bz2
rneovim-a1542b091dd7b919fa8524c1c909ef897dde9299.zip
Merge pull request #18353 from jamessan/ft-match-fix
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/filetype.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index f401de38f4..7679ed555f 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -1482,8 +1482,18 @@ end
local pattern_sorted = sort_by_priority(pattern)
---@private
-local function normalize_path(path)
- return (path:gsub("\\", "/"):gsub("^~", vim.env.HOME))
+local function normalize_path(path, as_pattern)
+ local normal = path:gsub("\\", '/')
+ if normal:find('^~') then
+ if as_pattern then
+ -- Escape Lua's metacharacters when $HOME is used in a pattern.
+ -- The rest of path should already be properly escaped.
+ normal = vim.env.HOME:gsub('[-^$()%%.%[%]+?]', '%%%0') .. normal:sub(2)
+ else
+ normal = vim.env.HOME .. normal:sub(2)
+ end
+ end
+ return normal
end
--- Add new filetype mappings.
@@ -1552,7 +1562,7 @@ function M.add(filetypes)
end
for k, v in pairs(filetypes.pattern or {}) do
- pattern[normalize_path(k)] = v
+ pattern[normalize_path(k, true)] = v
end
if filetypes.pattern then