]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(rustfmt): not correctly escaping directory names
authorChristian Brabandt <cb@256bit.org>
Mon, 30 Mar 2026 10:18:35 +0000 (10:18 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 30 Mar 2026 10:18:35 +0000 (10:18 +0000)
Problem:  runtime(rustfmt): not correctly escaping directory names
Solution: Use fnamescape() (MichaƂ Majchrowicz)

Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/rustfmt.vim

index 3d905296a6e92c8085efeb8c3684129b65bb30b3..771c95a877e7c9a8d6f507f109362c716173a005 100644 (file)
@@ -3,7 +3,7 @@
 " Last Change:
 " 2025 Oct 27 by Vim project: don't use rustfmt as 'formatprg' by default
 " 2026 Jan 25 by Vim project: don't hide rustfmt errors, restore default var
-"
+" 2026 Mar 30 by Vim project: use fnameescape for :chdir commands
 "
 " Adapted from https://github.com/fatih/vim-go
 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim
@@ -135,7 +135,7 @@ function! s:RunRustfmt(command, tmpname, from_writepre)
         " chdir to the directory of the file
         let l:has_lcd = haslocaldir()
         let l:prev_cd = getcwd()
-        execute 'lchdir! '.expand('%:h')
+        execute 'lchdir! ' . fnameescape(expand('%:h'))
 
         let l:buffer = getline(1, '$')
         if exists("*systemlist")
@@ -215,6 +215,7 @@ function! s:RunRustfmt(command, tmpname, from_writepre)
     endif
 
     " Restore the current directory if needed
+    let l:prev_cd = fnameescape(l:prev_cd)
     if a:tmpname ==# ''
         if l:has_lcd
             execute 'lchdir! '.l:prev_cd