Skip to content

Commit

Permalink
fix: shellescape hell
Browse files Browse the repository at this point in the history
refer: #151
  • Loading branch information
lervag committed May 12, 2021
1 parent a9db629 commit 24f0999
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion autoload/ctrlp/wiki.vim
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ function! ctrlp#wiki#init()
endfunction

function! ctrlp#wiki#accept(md, path)
call ctrlp#acceptfile(a:md, printf('%s/%s.%s', s:root, a:path, s:extension))
call ctrlp#acceptfile(a:md,
\ wiki#paths#s(printf('%s/%s.%s', s:root, a:path, s:extension)))
endfunction
3 changes: 2 additions & 1 deletion autoload/wiki/buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function! wiki#buffer#init() abort " {{{1
" Initialize the b:wiki state
let b:wiki = {}
let b:wiki.root = wiki#get_root()
let b:wiki.root_journal = printf('%s/%s', b:wiki.root, g:wiki_journal.name)
let b:wiki.root_journal = wiki#paths#s(
\ printf('%s/%s', b:wiki.root, g:wiki_journal.name))
let b:wiki.extension = expand('%:e')
let b:wiki.index_name = g:wiki_index_name
let b:wiki.link_extension = g:wiki_link_extension
Expand Down
7 changes: 4 additions & 3 deletions autoload/wiki/journal.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ endfunction
function! wiki#journal#copy_note() abort " {{{1
let l:next = s:get_next_entry()

let l:next_entry = printf('%s/%s.%s',
\ b:wiki.root_journal, l:next, b:wiki.extension)
let l:next_entry = wiki#paths#s(printf('%s/%s.%s',
\ b:wiki.root_journal, l:next, b:wiki.extension))
if !filereadable(l:next_entry)
execute 'write' l:next_entry
endif
Expand Down Expand Up @@ -135,7 +135,8 @@ endfunction

" }}}1
function! s:get_links_generic(rx, fmt) abort " {{{1
let l:globpat = printf('%s/*.%s', b:wiki.root_journal, b:wiki.extension)
let l:globpat = wiki#paths#s(printf('%s/*.%s',
\ b:wiki.root_journal, b:wiki.extension))
let l:links = filter(map(glob(l:globpat, 0, 1),
\ 'fnamemodify(v:val, '':t:r'')'),
\ 'v:val =~# a:rx')
Expand Down
4 changes: 2 additions & 2 deletions autoload/wiki/link/word.vim
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ function! s:matcher.toggle_template(words, _text) abort " {{{1


" First try local page
if filereadable(printf('%s/%s', expand('%:p:h'), l:url_actual))
if filereadable(wiki#paths#s(printf('%s/%s', expand('%:p:h'), l:url_actual)))
return wiki#link#template(l:url_target, a:words)
endif

" Next try at wiki root
if filereadable(printf('%s/%s', b:wiki.root, l:url_actual))
if filereadable(wiki#paths#s(printf('%s/%s', b:wiki.root, l:url_actual)))
return wiki#link#template('/' . l:url_target, a:words)
endif

Expand Down
6 changes: 3 additions & 3 deletions autoload/wiki/page.vim
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function! wiki#page#rename(newname, ...) abort "{{{1
end

let l:oldpath = expand('%:p')
let l:newpath = simplify(printf('%s/%s.%s',
let l:newpath = wiki#paths#s(printf('%s/%s.%s',
\ expand('%:p:h'), a:newname, b:wiki.extension))

" Check if current file exists
Expand Down Expand Up @@ -377,8 +377,8 @@ function! wiki#page#export(line1, line2, ...) abort " {{{1

" Determine output filename and extension
if empty(l:cfg.fname)
let l:cfg.fname = printf('%s/%s.%s',
\ l:cfg.output, expand('%:t:r'), l:cfg.ext)
let l:cfg.fname = wiki#paths#s(printf('%s/%s.%s',
\ l:cfg.output, expand('%:t:r'), l:cfg.ext))
else
let l:cfg.ext = fnamemodify(l:cfg.fname, ':e')
endif
Expand Down
10 changes: 10 additions & 0 deletions autoload/wiki/paths.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ endfunction

" }}}1

function! wiki#paths#s(path) abort " {{{1
" Handle shellescape issues and simplify path
let l:path = exists('+shellslash') && !&shellslash
\ ? tr(a:path, '/', '\')
\ : a:path

return simplify(l:path)
endfunction

" }}}1
function! wiki#paths#is_abs(path) abort " {{{1
return a:path =~# s:re_abs
endfunction
Expand Down
2 changes: 1 addition & 1 deletion autoload/wiki/url/adoc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function! wiki#url#adoc#handler(url) abort " {{{1
let l:root = empty(a:url.origin)
\ ? wiki#get_root()
\ : fnamemodify(a:url.origin, ':p:h')
let l:handler.path = simplify(printf('%s/%s', l:root, l:parts[0]))
let l:handler.path = wiki#paths#s(printf('%s/%s', l:root, l:parts[0]))
let l:handler.dir = fnamemodify(l:handler.path, ':p:h')
let l:handler.anchor = l:parts[1]
endif
Expand Down
2 changes: 1 addition & 1 deletion autoload/wiki/url/wiki.vim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function! wiki#url#wiki#resolver(fname, origin) abort " {{{1
\ : (empty(a:origin)
\ ? wiki#get_root()
\ : fnamemodify(a:origin, ':p:h')) . '/' . a:fname
let l:path = simplify(l:path)
let l:path = wiki#paths#s(l:path)

" Determine the proper extension (if necessary)
let l:extensions = wiki#u#uniq_unsorted(
Expand Down

0 comments on commit 24f0999

Please sign in to comment.