fix(glob): handling commas in letter pattern #34170

This commit is contained in:
Brynne Taylor
2025-06-03 21:36:44 +08:00
committed by GitHub
parent eeacd7bd71
commit 3991f14621
2 changed files with 3 additions and 2 deletions

View File

@@ -44,7 +44,7 @@ local bit = require('bit')
local M = {}
-- Basic patterns for matching glob components
local letter = m.P(1) - m.S(',*?[]{}/\\') -- Any character except special glob characters
local letter = m.P(1) - m.S('*?[]{}/\\') -- Any character except special glob characters
local slash = m.P '/' * m.Cc(m.P '/') -- Path separator with capture
local notslash = m.P(1) - m.P '/' -- Any character except path separator
local notcomma = m.P(1) - m.S(',\\') -- Any character except comma and backslash
@@ -370,7 +370,7 @@ g = m.P(g)
---@return vim.lpeg.Pattern #An |lua-lpeg| representation of the pattern
function M.to_lpeg(pattern)
local lpeg_pattern = g:match(pattern) --[[@as vim.lpeg.Pattern?]]
assert(lpeg_pattern, 'Invalid glob')
assert(lpeg_pattern, string.format('Invalid glob: %s', pattern))
return lpeg_pattern
end

View File

@@ -27,6 +27,7 @@ describe('glob', function()
eq(false, match('a', 'b'))
eq(false, match('.', 'a'))
eq(true, match('$', '$'))
eq(true, match('a,b', 'a,b'))
eq(true, match('/dir', '/dir'))
eq(true, match('dir/', 'dir/'))
eq(true, match('dir/subdir', 'dir/subdir'))