fix(filetype): false positive when matching directory buffer #40695

Problem:
URI buffer names can end with a slash, but slash-ended directory
matching should not preempt URI filetype patterns.

Solution:
Do not use the slash shortcut for names with URI schemes, so those
continue through normal filetype matching.

Co-authored-by: Adam Karafyllidis <akisarou90@gmail.com>
This commit is contained in:
Barrett Ruth
2026-07-11 17:19:44 -05:00
committed by GitHub
parent 4349c386db
commit 67af4141c8
2 changed files with 15 additions and 1 deletions

View File

@@ -3254,7 +3254,7 @@ function M.match(args)
end
if name then
if name:sub(-1) == '/' then
if name:sub(-1) == '/' and not name:find('^%a[%w+.-]*://') then
return 'directory'
end
name = normalize_path(name)

View File

@@ -82,6 +82,20 @@ describe('vim.filetype', function()
)
end)
it('matches URI buffer patterns ending in slash', function()
eq(
'example',
exec_lua(function()
vim.filetype.add({
pattern = {
['example://.*'] = 'example',
},
})
return vim.filetype.match({ filename = 'example:///tmp/example/' })
end)
)
end)
it('works without defined g:ft_ignore_pat', function()
local match_opts = { filename = 'unknown-ft', buf = api.nvim_create_buf(false, true) }
eq(