From 032e024f8ab9048286859be6b83349c5f1ece868 Mon Sep 17 00:00:00 2001 From: Tristan Knight Date: Mon, 23 Sep 2024 23:42:16 +0100 Subject: fix(filetype): handle .in files with no filename (#30487) Problem: fnamemodify with the :r flag will not strip extensions if the filename starts with a ".". This means that files named ".in" could cause an infinite loop. Solution: Add early return if the filename was not changed --- runtime/lua/vim/filetype.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 88609799bf..5cb554b83e 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -148,6 +148,9 @@ end local function detect_noext(path, bufnr) local root = fn.fnamemodify(path, ':r') + if root == path then + return + end return M.match({ buf = bufnr, filename = root }) end @@ -1383,8 +1386,7 @@ local extension = { ['dpkg-new'] = detect_noext, ['in'] = function(path, bufnr) if vim.fs.basename(path) ~= 'configure.in' then - local root = fn.fnamemodify(path, ':r') - return M.match({ buf = bufnr, filename = root }) + return detect_noext(path, bufnr) end end, new = detect_noext, -- cgit