From 67af4141c8344fc705d97d4d197219a0de2059d8 Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Sat, 11 Jul 2026 17:19:44 -0500 Subject: [PATCH] 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 --- runtime/lua/vim/filetype.lua | 2 +- test/functional/lua/filetype_spec.lua | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 1c355fe2e8..861b863270 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -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) diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua index 2593a08d71..efbac45570 100644 --- a/test/functional/lua/filetype_spec.lua +++ b/test/functional/lua/filetype_spec.lua @@ -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(