diff options
| author | emmanueltouzery <etouzery@gmail.com> | 2022-09-09 14:06:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-09 20:06:57 +0800 |
| commit | 8e65dbb6e187604cdaf0e0ef2e90c790760912e7 (patch) | |
| tree | 2fc78bea7a3c1045034a75f14b5e629ff91553d3 | |
| parent | docs: update server_configurations.md (diff) | |
| download | nvim-lspconfig-8e65dbb6e187604cdaf0e0ef2e90c790760912e7.tar nvim-lspconfig-8e65dbb6e187604cdaf0e0ef2e90c790760912e7.tar.gz nvim-lspconfig-8e65dbb6e187604cdaf0e0ef2e90c790760912e7.tar.bz2 nvim-lspconfig-8e65dbb6e187604cdaf0e0ef2e90c790760912e7.tar.lz nvim-lspconfig-8e65dbb6e187604cdaf0e0ef2e90c790760912e7.tar.xz nvim-lspconfig-8e65dbb6e187604cdaf0e0ef2e90c790760912e7.tar.zst nvim-lspconfig-8e65dbb6e187604cdaf0e0ef2e90c790760912e7.zip | |
fix: escape wildcards patterns when calling glob (#2111) (#2122)
| -rw-r--r-- | lua/lspconfig/util.lua | 7 | ||||
| -rw-r--r-- | test/lspconfig_spec.lua | 16 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 0729430f..119c1caf 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -99,6 +99,10 @@ end M.path = (function() local is_windows = uv.os_uname().version:match 'Windows' + local function escape_wildcards(path) + return path:gsub('([%[%]%?%*])', '\\%1') + end + local function sanitize(path) if is_windows then path = path:sub(1, 1):upper() .. path:sub(2) @@ -211,6 +215,7 @@ M.path = (function() local path_separator = is_windows and ';' or ':' return { + escape_wildcards = escape_wildcards, is_dir = is_dir, is_file = is_file, is_absolute = is_absolute, @@ -334,7 +339,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 diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index 8cea4a54..b899c09d 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -18,6 +18,22 @@ end) describe('lspconfig', function() describe('util', function() describe('path', function() + describe('escape_wildcards', function() + it('doesnt escape if not needed', function() + ok(exec_lua [[ + local lspconfig = require("lspconfig") + + return lspconfig.util.path.escape_wildcards('/usr/local/test/fname.lua') == '/usr/local/test/fname.lua' + ]]) + end) + it('escapes if needed', function() + ok(exec_lua [[ + local lspconfig = require("lspconfig") + + return lspconfig.util.path.escape_wildcards('/usr/local/test/[sq brackets] fname?*.lua') == '/usr/local/test/\\[sq brackets\\] fname\\?\\*.lua' + ]]) + end) + end) describe('exists', function() it('is present directory', function() ok(exec_lua [[ |
