summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-05-18 13:41:22 +0200
committerBram Moolenaar <Bram@vim.org>2019-05-18 13:41:22 +0200
commit6349e9411fd17f80c7aff9c678a8800647d34cfa (patch)
tree864908c652f6e0f5e074db2b2d38d3062ae90cc3
parent0d3cb73012332964e7a81d7afd1c21d393f45566 (diff)
downloadvim-git-6349e9411fd17f80c7aff9c678a8800647d34cfa.tar.gz
patch 8.1.1345: stuck in sandbox with ":s/../\=Function/gn"v8.1.1345
Problem: Stuck in sandbox with ":s/../\=Function/gn". Solution: Don't skip over code to restore sandbox. (Christian Brabandt)
-rw-r--r--src/ex_cmds.c15
-rw-r--r--src/testdir/test_substitute.vim11
-rw-r--r--src/version.c2
3 files changed, 19 insertions, 9 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index b99e54bce..3c9166d42 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -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)
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
index a58b56ec8..06bdc243d 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index c31a98b44..519427655 100644
--- a/src/version.c
+++ b/src/version.c
@@ -768,6 +768,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1345,
+/**/
1344,
/**/
1343,