Skip to content

Commit 6349e94

Browse files
committed
patch 8.1.1345: stuck in sandbox with ":s/../\=Function/gn"
Problem: Stuck in sandbox with ":s/../\=Function/gn". Solution: Don't skip over code to restore sandbox. (Christian Brabandt)
1 parent 0d3cb73 commit 6349e94

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/ex_cmds.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5555,28 +5555,25 @@ do_sub(exarg_T *eap)
55555555
#ifdef FEAT_EVAL
55565556
if (subflags.do_count)
55575557
{
5558-
/* prevent accidentally changing the buffer by a function */
5559-
save_ma = curbuf->b_p_ma;
5558+
// prevent accidentally changing the buffer by a function
55605559
curbuf->b_p_ma = FALSE;
55615560
sandbox++;
55625561
}
5563-
/* Save flags for recursion. They can change for e.g.
5564-
* :s/^/\=execute("s#^##gn") */
5562+
// Save flags for recursion. They can change for e.g.
5563+
// :s/^/\=execute("s#^##gn")
55655564
subflags_save = subflags;
5565+
save_ma = curbuf->b_p_ma;
55665566
#endif
5567-
/* get length of substitution part */
5567+
// get length of substitution part
55685568
sublen = vim_regsub_multi(&regmatch,
55695569
sub_firstlnum - regmatch.startpos[0].lnum,
55705570
sub, sub_firstline, FALSE, p_magic, TRUE);
55715571
#ifdef FEAT_EVAL
55725572
// If getting the substitute string caused an error, don't do
55735573
// the replacement.
5574-
if (aborting())
5575-
goto skip;
5576-
55775574
// Don't keep flags set by a recursive call.
55785575
subflags = subflags_save;
5579-
if (subflags.do_count)
5576+
if (aborting() || subflags.do_count)
55805577
{
55815578
curbuf->b_p_ma = save_ma;
55825579
if (sandbox > 0)

src/testdir/test_substitute.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,17 @@ func Test_nocatch_sub_failure_handling()
638638
call assert_equal(1, error_caught)
639639
call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
640640

641+
" Same, but using "n" flag so that "sandbox" gets set
642+
call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
643+
let error_caught = 0
644+
try
645+
%s/aaa/\=Foo()/gn
646+
catch
647+
let error_caught = 1
648+
endtry
649+
call assert_equal(1, error_caught)
650+
call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
651+
641652
bwipe!
642653
endfunc
643654

src/version.c

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

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1345,
770772
/**/
771773
1344,
772774
/**/

0 commit comments

Comments
 (0)