Skip to content

Commit

Permalink
Improve "g:NERDTreeQuickLook()"
Browse files Browse the repository at this point in the history
The following improvements were made...

  - Use variable sigils
  - Shorten a local variable name
  - Prefer an early return over testing for a negative
  - Switch to single quotes
  - Call "shellescape()" to pass a command argument [IMPORTANT!]

The final change is a critical fix for the security and reliability
of this function (see ":h system()").

Similar fixes for the other functions in this script will follow.
  • Loading branch information
lifecrisis committed Apr 8, 2020
1 parent 832bbaa commit 56cfbcf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions nerdtree_plugin/fs_menu.vim
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,13 @@ endfunction

" FUNCTION: NERDTreeQuickLook() {{{1
function! NERDTreeQuickLook()
let treenode = g:NERDTreeFileNode.GetSelected()
if treenode !=# {}
call system("qlmanage -p 2>/dev/null '" . treenode.path.str() . "'")
let l:node = g:NERDTreeFileNode.GetSelected()

if empty(l:node)
return
endif

call system('qlmanage -p 2>/dev/null ' . shellescape(l:node.path.str()))
endfunction

" FUNCTION: NERDTreeRevealInFinder() {{{1
Expand Down Expand Up @@ -428,4 +431,3 @@ function! NERDTreeExecuteFileLinux()
endfunction

" vim: set sw=4 sts=4 et fdm=marker:

0 comments on commit 56cfbcf

Please sign in to comment.