Skip to content

Commit 2834ebd

Browse files
matveytbrammool
authored andcommitted
patch 9.0.0396: :findrepl does not escape '&' and '~' properly
Problem: :findrepl does not escape '&' and '~' properly. Solution: Escape depending on the value of 'magic'. (closes #11067)
1 parent 635bb49 commit 2834ebd

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/gui.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5360,8 +5360,10 @@ gui_do_findrepl(
53605360
if (type == FRD_REPLACEALL)
53615361
{
53625362
ga_concat(&ga, (char_u *)"/");
5363-
// escape slash and backslash
5364-
p = vim_strsave_escaped(repl_text, (char_u *)"/\\");
5363+
// Escape slash and backslash.
5364+
// Also escape tilde and ampersand if 'magic' is set.
5365+
p = vim_strsave_escaped(repl_text,
5366+
p_magic ? (char_u *)"/\\~&" : (char_u *)"/\\");
53655367
if (p != NULL)
53665368
ga_concat(&ga, p);
53675369
vim_free(p);

src/testdir/test_gui.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,12 @@ func Test_gui_findrepl()
15801580
call test_gui_event('findrepl', args)
15811581
call assert_equal(['ONE two ONE', 'Twoo ONE two ONEo'], getline(1, '$'))
15821582

1583+
" Replace all instances with sub-replace specials
1584+
call cursor(1, 1)
1585+
let args = #{find_text: 'ONE', repl_text: '&~&', flags: 0x4, forward: 1}
1586+
call test_gui_event('findrepl', args)
1587+
call assert_equal(['&~& two &~&', 'Twoo &~& two &~&o'], getline(1, '$'))
1588+
15831589
" Invalid arguments
15841590
call assert_false(test_gui_event('findrepl', {}))
15851591
let args = #{repl_text: 'a', flags: 1, forward: 1}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ static char *(features[]) =
703703

704704
static int included_patches[] =
705705
{ /* Add new patch number below this line */
706+
/**/
707+
396,
706708
/**/
707709
395,
708710
/**/

0 commit comments

Comments
 (0)