From 8af28ab9cb9aef5249b74589b2850a51adaa277f Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Tue, 27 May 2025 21:56:29 +0800 Subject: [PATCH] fix(filetype): error when `vim.filetype.match{buf=fn.bufadd('a.sh')}` #34155 Problem: Error when `vim.filetype.match` a buffer with suffix `sh`. Solution: fallback to an empty string as buffer content. --- runtime/lua/vim/filetype/detect.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 54affc6b73..6e1f833424 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -1536,7 +1536,7 @@ local function sh(path, contents, name) end -- Get the name from the first line if not specified - name = name or contents[1] + name = name or contents[1] or '' if name:find('^csh$') or matchregex(name, [[^#!.\{-2,}\]]) then -- Some .sh scripts contain #!/bin/csh. return M.shell(path, contents, 'csh')