From e39da6a820d2a700904117d29f0dd476d64262cf Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Mon, 14 Apr 2025 15:58:53 +0100 Subject: fix(util): improve wildcard escaping #3690 The escape_wildcards function was enhanced to handle a broader range of special characters that could cause issues when used in pattern matching. This includes additional wildcards, pattern matching characters, shell special characters, the escape character itself, and whitespace. This change provides more robust path handling throughout the codebase when dealing with file paths that contain special characters. Co-authored-by: Justin M. Keyes --- lua/lspconfig/util.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index b99f8555..d23e47c2 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -93,7 +93,14 @@ function M.search_ancestors(startpath, func) end local function escape_wildcards(path) - return path:gsub('([%[%]%?%*])', '\\%1') + -- Escape all potentially problematic special characters + -- Covers: + -- - Wildcards and pattern matching: [ ] ? * $ ( ) ^ % . + - ~ + -- - Escape character: \ + -- - Shell special characters: ` ' " ; | & < > + -- - Whitespace: %s (spaces, tabs, etc.) + -- The gsub function replaces any matches with the same character preceded by a backslash + return path:gsub('([' .. vim.pesc('[]?*$()^%.+-~') .. '\\`\'";|&<>%s])', '\\%1') end function M.root_pattern(...) -- cgit v1.2.3-70-g09d2