Skip to content

Commit

Permalink
patch 9.0.0396: :findrepl does not escape '&' and '~' properly
Browse files Browse the repository at this point in the history
Problem:    :findrepl does not escape '&' and '~' properly.
Solution:   Escape depending on the value of 'magic'. (closes #11067)
  • Loading branch information
matveyt authored and brammool committed Sep 6, 2022
1 parent 635bb49 commit 2834ebd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -5360,8 +5360,10 @@ gui_do_findrepl(
if (type == FRD_REPLACEALL)
{
ga_concat(&ga, (char_u *)"/");
// escape slash and backslash
p = vim_strsave_escaped(repl_text, (char_u *)"/\\");
// Escape slash and backslash.
// Also escape tilde and ampersand if 'magic' is set.
p = vim_strsave_escaped(repl_text,
p_magic ? (char_u *)"/\\~&" : (char_u *)"/\\");
if (p != NULL)
ga_concat(&ga, p);
vim_free(p);
Expand Down
6 changes: 6 additions & 0 deletions src/testdir/test_gui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,12 @@ func Test_gui_findrepl()
call test_gui_event('findrepl', args)
call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$'))

" Replace all instances with sub-replace specials
call cursor(1, 1)
let args = #{find_text: 'ONE', repl_text: '&~&', flags: 0x4, forward: 1}
call test_gui_event('findrepl', args)
call assert_equal(['&~& two &~&', 'Twoo &~& two &~&o'], getline(1, '$'))

" Invalid arguments
call assert_false(test_gui_event('findrepl', {}))
let args = #{repl_text: 'a', flags: 1, forward: 1}
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
396,
/**/
395,
/**/
Expand Down

0 comments on commit 2834ebd

Please sign in to comment.