From 449b4f1ed6084f81a1d0c2c1136cd242ec938625 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 27 Jun 2017 17:44:12 +0900 Subject: [PATCH] Disallow using standard Vim plugin directory as plug home Close #646 --- README.md | 4 +++- plug.vim | 3 +++ test/workflow.vader | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e9da75a..aae46b8 100644 --- a/README.md +++ b/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 diff --git a/plug.vim b/plug.vim index a7f1030..e0dc78f 100644 --- a/plug.vim +++ b/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 = {} diff --git a/test/workflow.vader b/test/workflow.vader index 78887ac..29826da 100644 --- a/test/workflow.vader +++ b/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'