Disallow using standard Vim plugin directory as plug home

Close #646
This commit is contained in:
Junegunn Choi 2017-06-27 17:44:12 +09:00
parent 802b100415
commit 449b4f1ed6
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 13 additions and 1 deletions

View File

@ -83,7 +83,9 @@ Add a vim-plug section to your `~/.vimrc` (or `~/.config/nvim/init.vim` for Neov
#### Example #### Example
```vim ```vim
" Specify a directory for plugins (for Neovim: ~/.local/share/nvim/plugged) " Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged') call plug#begin('~/.vim/plugged')
" Make sure you use single quotes " Make sure you use single quotes

View File

@ -121,6 +121,9 @@ function! plug#begin(...)
else else
return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.') return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.')
endif endif
if fnamemodify(home, ':t') ==# 'plugin' && fnamemodify(home, ':h') ==# s:first_rtp
return s:err('Invalid plug home. '.home.' is a standard Vim runtime path and is not allowed.')
endif
let g:plug_home = home let g:plug_home = home
let g:plugs = {} let g:plugs = {}

View File

@ -19,6 +19,13 @@ Execute (plug#begin() without path argument with empty &rtp):
let &rtp = save_rtp let &rtp = save_rtp
unlet save_rtp unlet save_rtp
Execute (Standard runtime path is not allowed):
redir => out
silent! AssertEqual 0, plug#begin(split(&rtp, ',')[0].'/plugin')
redir END
Log out
Assert stridx(out, 'Invalid plug home') >= 0
Execute (plug#begin(path)): Execute (plug#begin(path)):
call plug#begin(g:temp_plugged.'/') call plug#begin(g:temp_plugged.'/')
Assert g:plug_home !~ '[/\\]$', 'Trailing / should be stripped from g:plug_home' Assert g:plug_home !~ '[/\\]$', 'Trailing / should be stripped from g:plug_home'