commit d2ca90d87e3246b5b827ed08f8c0dfc8ad6ae4c8
parent 025c0c34ce597484db01850cc1576b488bc84986
Author: Tristan Knight <admin@snappeh.com>
Date: Mon, 12 Jan 2026 18:58:01 +0000
fix(glob): handle numeric literals in pattern matching (#37257)
Problem:
vim.glob.to_lpeg() errors when patterns contain numeric literals
(like the '1' in '.ps*1') because LPeg interprets numeric strings
as indexed grammar rule references. For example:
vim.glob.to_lpeg('.ps*1')
E5108: Lua: rule '1' undefined in given grammar
Solution:
Prefix all rule names with '_' in the end_seg() function to prevent
literal numbers from being interpreted as LPeg indexed rules. This
ensures pattern components like '1', '2', etc. are treated as
regular rule names rather than special references.
Diffstat:
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/runtime/lua/vim/glob.lua b/runtime/lua/vim/glob.lua
@@ -96,7 +96,7 @@ local function end_seg(t)
if t.n > 0 then
seg_grammar.s = t.s
for i = 1, t.n do
- local rname = t[i][1]
+ local rname = '_' .. t[i][1]
if not seg_grammar[rname] then
-- Optimize search when deterministic first character is available
if t[i].F then
diff --git a/test/functional/lua/glob_spec.lua b/test/functional/lua/glob_spec.lua
@@ -67,6 +67,9 @@ describe('glob', function()
eq(true, match('a*b*[cy]*d*e*', 'axbxcxdxexxx'))
eq(true, match('a*b*[cy]*d*e*', 'axbxyxdxexxx'))
eq(true, match('a*b*[cy]*d*e*', 'axbxxxyxdxexxx'))
+ eq(true, match('.ps*1', '.ps1'))
+ eq(true, match('.ps*1', '.psaa1'))
+ eq(false, match('.ps*1', '.ps1a'))
end)
it('should match ? wildcards', function()