summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-10-31 04:38:36 +0100
committerBram Moolenaar <Bram@vim.org>2019-10-31 04:38:36 +0100
commitbb26596242fa7db477e2cd706dd99f9a426b5f71 (patch)
treea8d1d09b9bbf5d729b0ce6406963038dee2055a8
parent77ccc00340ed2598f7aa09716217e878665964fa (diff)
downloadvim-git-bb26596242fa7db477e2cd706dd99f9a426b5f71.tar.gz
patch 8.1.2236: ml_get error if pattern matches beyond last linev8.1.2236
Problem: Ml_get error if pattern matches beyond last line. Solution: Adjust position if needed. (Christian Brabandt, closes #5139)
-rw-r--r--src/ex_cmds.c5
-rw-r--r--src/testdir/test_substitute.vim10
-rw-r--r--src/version.c2
3 files changed, 17 insertions, 0 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index fc692e323..a7f80a80a 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3947,6 +3947,11 @@ do_sub(exarg_T *eap)
VIM_CLEAR(sub_firstline);
}
+ // Match might be after the last line for "\n\zs" matching at
+ // the end of the last line.
+ if (lnum > curbuf->b_ml.ml_line_count)
+ break;
+
if (sub_firstline == NULL)
{
sub_firstline = vim_strsave(ml_get(sub_firstlnum));
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
index 8a8e7ab4f..e8b0e49c2 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -413,6 +413,7 @@ func Run_SubCmd_Tests(tests)
for t in a:tests
let start = line('.') + 1
let end = start + len(t[2]) - 1
+ " TODO: why is there a one second delay the first time we get here?
exe "normal o" . t[0]
call cursor(start, 1)
exe t[1]
@@ -716,3 +717,12 @@ one two
close!
endfunc
+
+func Test_sub_beyond_end()
+ new
+ call setline(1, '#')
+ let @/ = '^#\n\zs'
+ s///e
+ call assert_equal('#', getline(1))
+ bwipe!
+endfunc
diff --git a/src/version.c b/src/version.c
index e8e2806a1..9766d656a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2236,
+/**/
2235,
/**/
2234,