mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	fix(filetype): don't use fnamemodify() with :e for extension (#27976)
Use pattern matching instead, as fnamemodify() with :e produces an empty string when the file name only has an extension, leading to differences in behavior from Vim. Related #16955 #27972
This commit is contained in:
		@@ -1472,7 +1472,6 @@ local filename = {
 | 
				
			|||||||
  ['bash.bashrc'] = detect.bash,
 | 
					  ['bash.bashrc'] = detect.bash,
 | 
				
			||||||
  bashrc = detect.bash,
 | 
					  bashrc = detect.bash,
 | 
				
			||||||
  ['.bashrc'] = detect.bash,
 | 
					  ['.bashrc'] = detect.bash,
 | 
				
			||||||
  ['.env'] = detect.sh,
 | 
					 | 
				
			||||||
  ['.kshrc'] = detect.ksh,
 | 
					  ['.kshrc'] = detect.ksh,
 | 
				
			||||||
  ['.profile'] = detect.sh,
 | 
					  ['.profile'] = detect.sh,
 | 
				
			||||||
  ['/etc/profile'] = detect.sh,
 | 
					  ['/etc/profile'] = detect.sh,
 | 
				
			||||||
@@ -2387,7 +2386,9 @@ function M.match(args)
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    -- Next, check file extension
 | 
					    -- Next, check file extension
 | 
				
			||||||
    local ext = fn.fnamemodify(name, ':e')
 | 
					    -- Don't use fnamemodify() with :e modifier here,
 | 
				
			||||||
 | 
					    -- as that's empty when there is only an extension.
 | 
				
			||||||
 | 
					    local ext = name:match('%.([^.]-)$') or ''
 | 
				
			||||||
    ft, on_detect = dispatch(extension[ext], path, bufnr)
 | 
					    ft, on_detect = dispatch(extension[ext], path, bufnr)
 | 
				
			||||||
    if ft then
 | 
					    if ft then
 | 
				
			||||||
      return ft, on_detect
 | 
					      return ft, on_detect
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user