mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-29 08:13:54 +00:00
[vim] Escape backslashes in fzf#shellescape (#1021)
This commit is contained in:
parent
87874bba88
commit
3399e39968
@ -66,8 +66,8 @@ function! s:shellesc_cmd(arg)
|
|||||||
let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g')
|
let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g')
|
||||||
let escaped = substitute(escaped, '%', '%%', 'g')
|
let escaped = substitute(escaped, '%', '%%', 'g')
|
||||||
let escaped = substitute(escaped, '"', '\\^&', 'g')
|
let escaped = substitute(escaped, '"', '\\^&', 'g')
|
||||||
let escaped = substitute(escaped, '\\\+\(\\^\)', '\\\\\1', 'g')
|
let escaped = substitute(escaped, '\(\\\+\)\(\\^\)', '\1\1\2', 'g')
|
||||||
return '^"'.substitute(escaped, '[^\\]\zs\\$', '\\\\', '').'^"'
|
return '^"'.substitute(escaped, '\(\\\+\)$', '\1\1', '').'^"'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#shellescape(arg, ...)
|
function! fzf#shellescape(arg, ...)
|
||||||
|
@ -149,16 +149,18 @@ Execute (fzf#wrap):
|
|||||||
|
|
||||||
Execute (fzf#shellescape with sh):
|
Execute (fzf#shellescape with sh):
|
||||||
AssertEqual '''''', fzf#shellescape('', 'sh')
|
AssertEqual '''''', fzf#shellescape('', 'sh')
|
||||||
|
AssertEqual '''\''', fzf#shellescape('\', 'sh')
|
||||||
AssertEqual '''""''', fzf#shellescape('""', 'sh')
|
AssertEqual '''""''', fzf#shellescape('""', 'sh')
|
||||||
AssertEqual '''foobar>''', fzf#shellescape('foobar>', 'sh')
|
AssertEqual '''foobar>''', fzf#shellescape('foobar>', 'sh')
|
||||||
AssertEqual '''\"''', fzf#shellescape('\"', 'sh')
|
AssertEqual '''\\\"\\\''', fzf#shellescape('\\\"\\\', 'sh')
|
||||||
AssertEqual '''echo ''\''''a''\'''' && echo ''\''''b''\''''''', fzf#shellescape('echo ''a'' && echo ''b''', 'sh')
|
AssertEqual '''echo ''\''''a''\'''' && echo ''\''''b''\''''''', fzf#shellescape('echo ''a'' && echo ''b''', 'sh')
|
||||||
|
|
||||||
Execute (fzf#shellescape with cmd.exe):
|
Execute (fzf#shellescape with cmd.exe):
|
||||||
AssertEqual '^"^"', fzf#shellescape('', 'cmd.exe')
|
AssertEqual '^"^"', fzf#shellescape('', 'cmd.exe')
|
||||||
|
AssertEqual '^"\\^"', fzf#shellescape('\', 'cmd.exe')
|
||||||
AssertEqual '^"\^"\^"^"', fzf#shellescape('""', 'cmd.exe')
|
AssertEqual '^"\^"\^"^"', fzf#shellescape('""', 'cmd.exe')
|
||||||
AssertEqual '^"foobar^>^"', fzf#shellescape('foobar>', 'cmd.exe')
|
AssertEqual '^"foobar^>^"', fzf#shellescape('foobar>', 'cmd.exe')
|
||||||
AssertEqual '^"\\\^"\\^"', fzf#shellescape('\\\\\\\\"\', 'cmd.exe')
|
AssertEqual '^"\\\\\\\^"\\\\\\^"', fzf#shellescape('\\\"\\\', 'cmd.exe')
|
||||||
AssertEqual '^"echo ''a'' ^&^& echo ''b''^"', fzf#shellescape('echo ''a'' && echo ''b''', 'cmd.exe')
|
AssertEqual '^"echo ''a'' ^&^& echo ''b''^"', fzf#shellescape('echo ''a'' && echo ''b''', 'cmd.exe')
|
||||||
|
|
||||||
AssertEqual '^"C:\Program Files ^(x86^)\\^"', fzf#shellescape('C:\Program Files (x86)\', 'cmd.exe')
|
AssertEqual '^"C:\Program Files ^(x86^)\\^"', fzf#shellescape('C:\Program Files (x86)\', 'cmd.exe')
|
||||||
|
Loading…
Reference in New Issue
Block a user