Browse Source

Disallow using standard Vim plugin directory as plug home

Close #646
Junegunn Choi 8 years ago
parent
commit
449b4f1ed6
3 changed files with 13 additions and 1 deletions
  1. 3 1
      README.md
  2. 3 0
      plug.vim
  3. 7 0
      test/workflow.vader

+ 3 - 1
README.md

@@ -83,7 +83,9 @@ Add a vim-plug section to your `~/.vimrc` (or `~/.config/nvim/init.vim` for Neov
 #### Example
 
 ```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')
 
 " Make sure you use single quotes

+ 3 - 0
plug.vim

@@ -121,6 +121,9 @@ function! plug#begin(...)
   else
     return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.')
   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:plugs = {}

+ 7 - 0
test/workflow.vader

@@ -19,6 +19,13 @@ Execute (plug#begin() without path argument with empty &rtp):
   let &rtp = 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)):
   call plug#begin(g:temp_plugged.'/')
   Assert g:plug_home !~ '[/\\]$', 'Trailing / should be stripped from g:plug_home'