diff options
| author | ryoppippi <1560508+ryoppippi@users.noreply.github.com> | 2025-04-14 15:58:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-14 07:58:53 -0700 |
| commit | e39da6a820d2a700904117d29f0dd476d64262cf (patch) | |
| tree | 0981ca1e80a71ada91d55040dd3199760855905b /lua | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-e39da6a820d2a700904117d29f0dd476d64262cf.tar nvim-lspconfig-e39da6a820d2a700904117d29f0dd476d64262cf.tar.gz nvim-lspconfig-e39da6a820d2a700904117d29f0dd476d64262cf.tar.bz2 nvim-lspconfig-e39da6a820d2a700904117d29f0dd476d64262cf.tar.lz nvim-lspconfig-e39da6a820d2a700904117d29f0dd476d64262cf.tar.xz nvim-lspconfig-e39da6a820d2a700904117d29f0dd476d64262cf.tar.zst nvim-lspconfig-e39da6a820d2a700904117d29f0dd476d64262cf.zip | |
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 <justinkz@gmail.com>
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/util.lua | 9 |
1 files changed, 8 insertions, 1 deletions
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(...) |
