]> granicus.if.org Git - vim/commitdiff
patch 8.1.1345: stuck in sandbox with ":s/../\=Function/gn" v8.1.1345
authorBram Moolenaar <Bram@vim.org>
Sat, 18 May 2019 11:41:22 +0000 (13:41 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 18 May 2019 11:41:22 +0000 (13:41 +0200)
Problem:    Stuck in sandbox with ":s/../\=Function/gn".
Solution:   Don't skip over code to restore sandbox. (Christian Brabandt)

src/ex_cmds.c
src/testdir/test_substitute.vim
src/version.c

index b99e54bce3dc29b868a6bdb263bdfcf941e89f6e..3c9166d42400160e0aab014db1cdc5467143fda4 100644 (file)
@@ -5555,28 +5555,25 @@ do_sub(exarg_T *eap)
 #ifdef FEAT_EVAL
                if (subflags.do_count)
                {
-                   /* prevent accidentally changing the buffer by a function */
-                   save_ma = curbuf->b_p_ma;
+                   // prevent accidentally changing the buffer by a function
                    curbuf->b_p_ma = FALSE;
                    sandbox++;
                }
-               /* Save flags for recursion.  They can change for e.g.
-                * :s/^/\=execute("s#^##gn") */
+               // Save flags for recursion.  They can change for e.g.
+               // :s/^/\=execute("s#^##gn")
                subflags_save = subflags;
+               save_ma = curbuf->b_p_ma;
 #endif
-               /* get length of substitution part */
+               // get length of substitution part
                sublen = vim_regsub_multi(&regmatch,
                                    sub_firstlnum - regmatch.startpos[0].lnum,
                                    sub, sub_firstline, FALSE, p_magic, TRUE);
 #ifdef FEAT_EVAL
                // If getting the substitute string caused an error, don't do
                // the replacement.
-               if (aborting())
-                   goto skip;
-
                // Don't keep flags set by a recursive call.
                subflags = subflags_save;
-               if (subflags.do_count)
+               if (aborting() || subflags.do_count)
                {
                    curbuf->b_p_ma = save_ma;
                    if (sandbox > 0)
index a58b56ec895e992e37383f2d333ee11337fa33b7..06bdc243db957ee53f40deb44a0a6876f4a757ef 100644 (file)
@@ -638,6 +638,17 @@ func Test_nocatch_sub_failure_handling()
   call assert_equal(1, error_caught)
   call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
 
+  " Same, but using "n" flag so that "sandbox" gets set
+  call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
+  let error_caught = 0
+  try
+    %s/aaa/\=Foo()/gn
+  catch
+    let error_caught = 1
+  endtry
+  call assert_equal(1, error_caught)
+  call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
+
   bwipe!
 endfunc
 
index c31a98b449e0950c76f81993b907b03b7d83fc81..519427655418e3bfd885b16af05fe79cd04642b4 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1345,
 /**/
     1344,
 /**/