Skip to content

Commit d1c8d2d

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0692: Wrong patlen value in ex_substitute()
Problem: Wrong patlen value in ex_substitute() (after 9.1.0426). Solution: Compute patlen after finding end separator. (zeertzjq) Add a more explicit test. The test already passes as the only case where a overlarge patlen value matters was fixed by patch 9.1.0689. closes: #15565 Signed-off-by: zeertzjq <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 3f7024c commit d1c8d2d

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/ex_cmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3841,11 +3841,11 @@ ex_substitute(exarg_T *eap)
38413841
which_pat = RE_LAST; // use last used regexp
38423842
delimiter = *cmd++; // remember delimiter character
38433843
pat = cmd; // remember start of search pat
3844-
patlen = STRLEN(pat);
38453844
cmd = skip_regexp_ex(cmd, delimiter, magic_isset(),
38463845
&eap->arg, NULL, NULL);
38473846
if (cmd[0] == delimiter) // end delimiter found
38483847
*cmd++ = NUL; // replace it with a NUL
3848+
patlen = STRLEN(pat);
38493849
}
38503850

38513851
/*

src/testdir/test_search.vim

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,37 @@ func Test_search_with_no_last_pat()
17471747
call delete('Xresult')
17481748
endfunc
17491749

1750+
" Test for using the last substitute pattern without last search pattern.
1751+
func Test_search_with_last_substitute_pat()
1752+
let lines =<< trim [SCRIPT]
1753+
new
1754+
set shortmess+=S
1755+
call setline(1, repeat(['foofoo'], 3))
1756+
%s/foo/bar/
1757+
call assert_equal(repeat(['barfoo'], 3), getline(1, '$'))
1758+
1759+
call cursor(1, 1)
1760+
call assert_equal("/foo", execute('call feedkeys("/\r", "tx")', '')->trim())
1761+
call assert_equal([0, 1, 4, 0], getpos('.'))
1762+
1763+
if has('rightleft')
1764+
set rightleft rightleftcmd=search
1765+
call cursor(1, 1)
1766+
call assert_equal("oof/", execute('call feedkeys("/\r", "tx")', '')->trim())
1767+
call assert_equal([0, 1, 4, 0], getpos('.'))
1768+
endif
1769+
1770+
call writefile(v:errors, 'Xresult')
1771+
qall!
1772+
[SCRIPT]
1773+
call writefile(lines, 'Xscript', 'D')
1774+
1775+
if RunVim([], [], '--clean -S Xscript')
1776+
call assert_equal([], readfile('Xresult'))
1777+
endif
1778+
call delete('Xresult')
1779+
endfunc
1780+
17501781
" Test for using tilde (~) atom in search. This should use the last used
17511782
" substitute pattern
17521783
func Test_search_tilde_pat()

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
692,
707709
/**/
708710
691,
709711
/**/

0 commit comments

Comments
 (0)