]> granicus.if.org Git - vim/commitdiff
patch 9.0.0396: :findrepl does not escape '&' and '~' properly v9.0.0396
authormatveyt <matthewtarasov@yandex.ru>
Tue, 6 Sep 2022 16:00:15 +0000 (17:00 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 6 Sep 2022 16:00:15 +0000 (17:00 +0100)
Problem:    :findrepl does not escape '&' and '~' properly.
Solution:   Escape depending on the value of 'magic'. (closes #11067)

src/gui.c
src/testdir/test_gui.vim
src/version.c

index 9c78dacb1a10945c081444762a9d0fded9d5a912..b9217b45909ba31d96ca5a9e852918c8fa4c7f17 100644 (file)
--- a/src/gui.c
+++ b/src/gui.c
@@ -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);
index 29e4ecdd5be34957620fbe76b66dca85e371c514..a2491458dd65e1e52e132cb81c9c60c8580dc3a6 100644 (file)
@@ -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}
index 2cf848c63a77429c81797a7de9ef831b1bfb90fa..f1170220cfdc7dfa147aa836df1e7c3c325729d9 100644 (file)
@@ -703,6 +703,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    396,
 /**/
     395,
 /**/