]> granicus.if.org Git - vim/commitdiff
patch 8.1.2236: ml_get error if pattern matches beyond last line v8.1.2236
authorBram Moolenaar <Bram@vim.org>
Thu, 31 Oct 2019 03:38:36 +0000 (04:38 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 31 Oct 2019 03:38:36 +0000 (04:38 +0100)
Problem:    Ml_get error if pattern matches beyond last line.
Solution:   Adjust position if needed. (Christian Brabandt, closes #5139)

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

index fc692e32359880c0330f1adfaaeb8b298e4d8b46..a7f80a80a8580222657037a3fd289f402e31d392 100644 (file)
@@ -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));
index 8a8e7ab4f8096ae1800a3319aa86e2a64719e0ae..e8b0e49c2e402a8e044eeaea431209668a1c5bb3 100644 (file)
@@ -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
index e8e2806a178fe1cd7c513b75f20fba94242ca97e..9766d656a4c6ea1dcdcfd3008b334edac326ef3a 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2236,
 /**/
     2235,
 /**/