Skip to content
Myr

[vim] Escape backslashes in fzf#shellescape (#1021)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jan Edmund Lazo · committed by Junegunn Choi · parent 87874bb · Browse files · 2 files+6 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+6 added−4 removed

  • tests:+4 added−2 removed
  • other:+2 added−2 removed

2 files+6 added−4 removed

modified:plugin/fzf.vim+2 added-2 removed
64 unmodified lines
65function! s:shellesc_cmd(arg)66 let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g')67 let escaped = substitute(escaped, '%', '%%', 'g')68 let escaped = substitute(escaped, '"', '\\^&', 'g')69 let escaped = substitute(escaped, '\\\+\(\\^\)', '\\\\\1', 'g')70 return '^"'.substitute(escaped, '[^\\]\zs\\$', '\\\\', '').'^"'69 let escaped = substitute(escaped, '\(\\\+\)\(\\^\)', '\1\1\2', 'g')70 return '^"'.substitute(escaped, '\(\\\+\)$', '\1\1', '').'^"'71endfunction7273function! fzf#shellescape(arg, ...)74 let shell = get(a:000, 0, &shell)
711 unmodified lines
modified:test/fzf.vader+4 added-2 removed
147 unmodified lines
148 Assert opts.options =~ '^--color=fg:'149150Execute (fzf#shellescape with sh):151 AssertEqual '''''', fzf#shellescape('', 'sh')152 AssertEqual '''\''', fzf#shellescape('\', 'sh')153 AssertEqual '''""''', fzf#shellescape('""', 'sh')154 AssertEqual '''foobar>''', fzf#shellescape('foobar>', 'sh')154 AssertEqual '''\"''', fzf#shellescape('\"', 'sh')155 AssertEqual '''\\\"\\\''', fzf#shellescape('\\\"\\\', 'sh')156 AssertEqual '''echo ''\''''a''\'''' && echo ''\''''b''\''''''', fzf#shellescape('echo ''a'' && echo ''b''', 'sh')157158Execute (fzf#shellescape with cmd.exe):159 AssertEqual '^"^"', fzf#shellescape('', 'cmd.exe')160 AssertEqual '^"\\^"', fzf#shellescape('\', 'cmd.exe')161 AssertEqual '^"\^"\^"^"', fzf#shellescape('""', 'cmd.exe')162 AssertEqual '^"foobar^>^"', fzf#shellescape('foobar>', 'cmd.exe')161 AssertEqual '^"\\\^"\\^"', fzf#shellescape('\\\\\\\\"\', 'cmd.exe')163 AssertEqual '^"\\\\\\\^"\\\\\\^"', fzf#shellescape('\\\"\\\', 'cmd.exe')164 AssertEqual '^"echo ''a'' ^&^& echo ''b''^"', fzf#shellescape('echo ''a'' && echo ''b''', 'cmd.exe')165166 AssertEqual '^"C:\Program Files ^(x86^)\\^"', fzf#shellescape('C:\Program Files (x86)\', 'cmd.exe')167 AssertEqual '^"C:/Program Files ^(x86^)/^"', fzf#shellescape('C:/Program Files (x86)/', 'cmd.exe')
5 unmodified lines