quickfix.vim (1143B)
1 " Last Modified: 2023-09-11 2 " 2026 Oct 15 by Vim project: Fix code injection via crafted directory names 3 4 function! cargo#quickfix#CmdPre() abort 5 if &filetype ==# 'rust' && get(b:, 'current_compiler', '') ==# 'cargo' && 6 \ &makeprg =~ '\V\^cargo\ \.\*' 7 " Preserve the current directory, and 'lcd' to the nearest Cargo file. 8 let b:rust_compiler_cargo_qf_has_lcd = haslocaldir() 9 let b:rust_compiler_cargo_qf_prev_cd = getcwd() 10 let b:rust_compiler_cargo_qf_prev_cd_saved = 1 11 let nearest = fnamemodify(cargo#nearestRootCargo(0), ':h') 12 call chdir(nearest, 'window') 13 else 14 let b:rust_compiler_cargo_qf_prev_cd_saved = 0 15 endif 16 endfunction 17 18 function! cargo#quickfix#CmdPost() abort 19 if exists("b:rust_compiler_cargo_qf_prev_cd_saved") && b:rust_compiler_cargo_qf_prev_cd_saved 20 " Restore the current directory. 21 let scope = ['global', 'window', 'tabpage'] 22 call chdir(b:rust_compiler_cargo_qf_prev_cd, scope[b:rust_compiler_cargo_qf_has_lcd]) 23 let b:rust_compiler_cargo_qf_prev_cd_saved = 0 24 endif 25 endfunction 26 27 " vim: set et sw=4 sts=4 ts=8: