diff src/gui.c @ 30120:eb534258bdaf v9.0.0396

patch 9.0.0396: :findrepl does not escape '&' and '~' properly Commit: https://github.com/vim/vim/commit/2834ebdee473c838e50e60d0aa160f0e62fc8ef9 Author: matveyt <matthewtarasov@yandex.ru> Date: Tue Sep 6 17:00:15 2022 +0100 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 https://github.com/vim/vim/issues/11067)
author Bram Moolenaar <Bram@vim.org>
date Tue, 06 Sep 2022 18:15:03 +0200
parents be5b8d4616b2
children 101f08b49ed3
line wrap: on
line diff
--- 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);