Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve filename and path escaping

Refs #281
  • Loading branch information...
commit 10bbbfa7baeb77c00b87b6a8d09f1a6e2af3c148 1 parent 51e2614
@kien authored
View
41 autoload/ctrlp.vim
@@ -147,8 +147,6 @@ if !has('gui_running')
cal add(s:prtmaps['PrtBS()'], remove(s:prtmaps['PrtCurLeft()'], 0))
en
-let s:lash = ctrlp#utils#lash()
-
let s:compare_lim = 3000
let s:ficounts = {}
@@ -222,6 +220,7 @@ fu! s:opts(...)
let s:mxheight = max([s:mxheight, 1])
let s:glob = s:showhidden ? '.*\|*' : '*'
let s:igntype = empty(s:usrign) ? -1 : type(s:usrign)
+ let s:lash = ctrlp#utils#lash()
if s:keyloop
let [s:lazy, s:glbs['imd']] = [0, 0]
en
@@ -290,12 +289,12 @@ fu! ctrlp#clr(...)
endf
fu! ctrlp#clra()
- let cache_dir = ctrlp#utils#cachedir()
- if isdirectory(cache_dir)
- let cache_files = split(s:glbpath(cache_dir, '**', 1), "\n")
+ let cadir = ctrlp#utils#cachedir()
+ if isdirectory(cadir)
+ let cafiles = split(s:glbpath(s:fnesc(cadir, 'g', ','), '**', 1), "\n")
let eval = '!isdirectory(v:val) && fnamemodify(v:val, ":t") !~'
\ . ' ''\v^<cache>[.a-z]+$|\.log$'''
- sil! cal map(filter(cache_files, eval), 'delete(v:val)')
+ sil! cal map(filter(cafiles, eval), 'delete(v:val)')
en
cal ctrlp#clr()
endf
@@ -314,7 +313,7 @@ fu! ctrlp#files()
let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
" Get the list of files
if empty(lscmd)
- cal s:GlobPath(s:dyncwd, 0)
+ cal s:GlobPath(s:fnesc(s:dyncwd, 'g', ','), 0)
el
sil! cal ctrlp#progress('Indexing...')
try | cal s:UserCmd(lscmd)
@@ -345,7 +344,7 @@ fu! s:GlobPath(dirs, depth)
cal extend(g:ctrlp_allfiles, dnf[1])
if !empty(dnf[0]) && !s:maxf(len(g:ctrlp_allfiles)) && depth <= s:maxdepth
sil! cal ctrlp#progress(len(g:ctrlp_allfiles), 1)
- cal s:GlobPath(join(dnf[0], ','), depth)
+ cal s:GlobPath(join(map(dnf[0], 's:fnesc(v:val, "g", ",")'), ','), depth)
en
endf
@@ -1316,7 +1315,7 @@ endf
fu! s:dircompl(be, sd)
if a:sd == '' | retu [] | en
let [be, sd] = a:be == '' ? [s:dyncwd, a:sd] : [a:be, a:be.s:lash(a:be).a:sd]
- let dirs = ctrlp#rmbasedir(split(globpath(be, a:sd.'*/'), "\n"))
+ let dirs = ctrlp#rmbasedir(split(globpath(s:fnesc(be, 'g', ','), a:sd.'*/'), "\n"))
cal filter(dirs, '!match(v:val, escape(sd, ''~$.\''))'
\ . ' && v:val !~ ''\v(^|[\/])\.{1,2}[\/]$''')
retu dirs
@@ -1405,10 +1404,13 @@ endf
fu! s:findroot(curr, mark, depth, type)
let [depth, fnd] = [a:depth + 1, 0]
if type(a:mark) == 1
- let fnd = s:glbpath(a:curr, a:mark, 1) != ''
+ let fnd = s:glbpath(s:fnesc(a:curr, 'g', ','), a:mark, 1) != ''
elsei type(a:mark) == 3
for markr in a:mark
- if s:glbpath(a:curr, markr, 1) != '' | let fnd = 1 | brea | en
+ if s:glbpath(s:fnesc(a:curr, 'g', ','), markr, 1) != ''
+ let fnd = 1
+ brea
+ en
endfo
en
if fnd
@@ -1427,17 +1429,16 @@ endf
fu! ctrlp#setdir(path, ...)
let cmd = a:0 ? a:1 : 'lc!'
- sil! exe cmd ctrlp#fnesc(a:path)
+ sil! exe cmd s:fnesc(a:path, 'c')
let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
endf
" Fallbacks {{{3
fu! s:glbpath(...)
- let cond = v:version > 702 || ( v:version == 702 && has('patch051') )
- retu call('globpath', cond ? a:000 : a:000[:1])
+ retu call('ctrlp#utils#globpath', a:000)
endf
-fu! ctrlp#fnesc(path)
- retu exists('*fnameescape') ? fnameescape(a:path) : escape(a:path, " %#*?|<\"\n")
+fu! s:fnesc(...)
+ retu call('ctrlp#utils#fnesc', a:000)
endf
fu! ctrlp#setlcdir()
@@ -1768,10 +1769,10 @@ fu! s:getinput(...)
endf
fu! s:migemo(str)
- let str = a:str
- let dict = s:glbpath(&rtp, printf("dict/%s/migemo-dict", &enc), 1)
+ let [str, rtp] = [a:str, s:fnesc(&rtp, 'g')]
+ let dict = s:glbpath(rtp, printf("dict/%s/migemo-dict", &enc), 1)
if !len(dict)
- let dict = s:glbpath(&rtp, "dict/migemo-dict", 1)
+ let dict = s:glbpath(rtp, "dict/migemo-dict", 1)
en
if len(dict)
let [tokens, str, cmd] = [split(str, '\s'), '', 'cmigemo -v -w %s -d %s']
@@ -1872,7 +1873,7 @@ fu! s:openfile(cmd, fid, tail, chkmod, ...)
en
let cmd = cmd =~ '^tab' ? ctrlp#tabcount().cmd : cmd
let j2l = a:0 && a:1[0] ? a:1[1] : 0
- exe cmd.( a:0 && a:1[0] ? '' : a:tail ) ctrlp#fnesc(a:fid)
+ exe cmd.( a:0 && a:1[0] ? '' : a:tail ) s:fnesc(a:fid, 'f')
if j2l
cal ctrlp#j2l(j2l)
en
View
3  autoload/ctrlp/dir.vim
@@ -32,6 +32,7 @@ fu! s:globdirs(dirs, depth)
let nr = len(g:ctrlp_alldirs)
if !empty(dirs) && !s:max(nr, s:maxfiles) && depth <= s:maxdepth
sil! cal ctrlp#progress(nr)
+ cal map(dirs, 'ctrlp#utils#fnesc(v:val, "g", ",")')
cal s:globdirs(join(dirs, ','), depth)
en
endf
@@ -53,7 +54,7 @@ fu! ctrlp#dir#init(...)
let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile('dir')
if g:ctrlp_newdir || s:nocache() || !filereadable(cafile)
let [s:initcwd, g:ctrlp_alldirs] = [s:cwd, []]
- cal s:globdirs(s:cwd, 0)
+ cal s:globdirs(ctrlp#utils#fnesc(s:cwd, 'g', ','), 0)
cal ctrlp#rmbasedir(g:ctrlp_alldirs)
if len(g:ctrlp_alldirs) <= s:compare_lim
cal sort(g:ctrlp_alldirs, 'ctrlp#complen')
View
17 autoload/ctrlp/rtscript.vim
@@ -24,23 +24,26 @@ let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
let s:filecounts = {}
" Utilities {{{1
fu! s:nocache()
- retu !s:caching || ( s:caching > 1 && get(s:filecounts, s:cwd) < s:caching )
+ retu g:ctrlp_newrts ||
+ \ !s:caching || ( s:caching > 1 && get(s:filecounts, s:cwd) < s:caching )
endf
" Public {{{1
fu! ctrlp#rtscript#init(caching)
let [s:caching, s:cwd] = [a:caching, getcwd()]
- if g:ctrlp_newrts || s:nocache()
- \ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[0] == &rtp )
+ if s:nocache() ||
+ \ !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[0] == &rtp )
sil! cal ctrlp#progress('Indexing...')
- let entries = split(globpath(&rtp, '**/*.*'), "\n")
+ let entries = split(globpath(ctrlp#utils#fnesc(&rtp, 'g'), '**/*.*'), "\n")
cal filter(entries, 'count(entries, v:val) == 1')
let [entries, echoed] = [ctrlp#dirnfile(entries)[1], 1]
el
let [entries, results] = g:ctrlp_rtscache[2:3]
en
- if g:ctrlp_newrts || s:nocache()
- \ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, s:cwd] )
- if !exists('echoed') | sil! cal ctrlp#progress('Processing...') | en
+ if s:nocache() ||
+ \ !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, s:cwd] )
+ if !exists('echoed')
+ sil! cal ctrlp#progress('Processing...')
+ en
let results = map(copy(entries), 'fnamemodify(v:val, '':.'')')
en
let [g:ctrlp_rtscache, g:ctrlp_newrts] = [[&rtp, s:cwd, entries, results], 0]
View
52 autoload/ctrlp/utils.vim
@@ -8,25 +8,28 @@
fu! ctrlp#utils#lash()
retu &ssl || !exists('+ssl') ? '/' : '\'
endf
-let s:lash = ctrlp#utils#lash()
fu! s:lash(...)
retu ( a:0 ? a:1 : getcwd() ) !~ '[\/]$' ? s:lash : ''
endf
fu! ctrlp#utils#opts()
+ let s:lash = ctrlp#utils#lash()
let usrhome = $HOME.s:lash($HOME)
let cahome = exists('$XDG_CACHE_HOME') ? $XDG_CACHE_HOME : usrhome.'.cache'
- let s:cache_dir = isdirectory(usrhome.'.ctrlp_cache')
+ let cadir = isdirectory(usrhome.'.ctrlp_cache')
\ ? usrhome.'.ctrlp_cache' : cahome.s:lash(cahome).'ctrlp'
if exists('g:ctrlp_cache_dir')
- let s:cache_dir = expand(g:ctrlp_cache_dir, 1)
- if isdirectory(s:cache_dir.s:lash(s:cache_dir).'.ctrlp_cache')
- let s:cache_dir = s:cache_dir.s:lash(s:cache_dir).'.ctrlp_cache'
+ let cadir = expand(g:ctrlp_cache_dir, 1)
+ if isdirectory(cadir.s:lash(cadir).'.ctrlp_cache')
+ let cadir = cadir.s:lash(cadir).'.ctrlp_cache'
en
en
+ let s:cache_dir = cadir
endf
cal ctrlp#utils#opts()
+
+let s:wig_cond = v:version > 702 || ( v:version == 702 && has('patch051') )
" Files and Directories {{{1
fu! ctrlp#utils#cachedir()
retu s:cache_dir
@@ -64,8 +67,43 @@ fu! ctrlp#utils#writecache(lines, ...)
endf
fu! ctrlp#utils#glob(...)
- let cond = v:version > 702 || ( v:version == 702 && has('patch051') )
- retu call('glob', cond ? a:000 : [a:1])
+ let path = ctrlp#utils#fnesc(a:1, 'g')
+ retu s:wig_cond ? glob(path, a:2) : glob(path)
+endf
+
+fu! ctrlp#utils#globpath(...)
+ retu call('globpath', s:wig_cond ? a:000 : a:000[:1])
+endf
+
+fu! ctrlp#utils#fnesc(path, type, ...)
+ if exists('*fnameescape')
+ if exists('+ssl')
+ if a:type == 'c'
+ let path = escape(a:path, '%#')
+ elsei a:type == 'f'
+ let path = fnameescape(a:path)
+ elsei a:type == 'g'
+ let path = escape(a:path, '?*')
+ en
+ let path = substitute(path, '[', '[[]', 'g')
+ el
+ let path = fnameescape(a:path)
+ en
+ el
+ if exists('+ssl')
+ if a:type == 'c'
+ let path = escape(a:path, '%#')
+ elsei a:type == 'f'
+ let path = escape(a:path, " \t\n%#*?|<\"")
+ elsei a:type == 'g'
+ let path = escape(a:path, '?*')
+ en
+ let path = substitute(path, '[', '[[]', 'g')
+ el
+ let path = escape(a:path, " \t\n*?[{`$\\%#'\"|!<")
+ en
+ en
+ retu a:0 ? escape(path, a:1) : path
endf
"}}}
Please sign in to comment.
Something went wrong with that request. Please try again.