0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.1.2125: fnamemodify() fails when repeating :e

Problem:    Fnamemodify() fails when repeating :e.
Solution:   Do not go before the tail. (Rob Pilling, closes #5024)
This commit is contained in:
Bram Moolenaar 2019-10-08 23:26:50 +02:00
parent 345f28df54
commit b189295b72
3 changed files with 35 additions and 1 deletions

View File

@ -563,7 +563,11 @@ repeat:
}
else // :r
{
if (s > tail) // remove one extension
char_u *limit = *fnamep;
if (limit < tail)
limit = tail;
if (s > limit) // remove one extension
*fnamelen = (int)(s - *fnamep);
}
*usedlen += 2;

View File

@ -45,3 +45,31 @@ func Test_fnamemodify()
let $HOME = save_home
let &shell = save_shell
endfunc
func Test_fnamemodify_er()
call assert_equal("with", fnamemodify("path/to/file.with.extensions", ':e:e:r:r'))
call assert_equal('c', fnamemodify('a.c', ':e'))
call assert_equal('c', fnamemodify('a.c', ':e:e'))
call assert_equal('c', fnamemodify('a.c', ':e:e:r'))
call assert_equal('c', fnamemodify('a.c', ':e:e:r:r'))
call assert_equal('rb', fnamemodify('a.spec.rb', ':e:r'))
call assert_equal('rb', fnamemodify('a.spec.rb', ':e:r'))
call assert_equal('spec.rb', fnamemodify('a.spec.rb', ':e:e'))
call assert_equal('spec', fnamemodify('a.spec.rb', ':e:e:r'))
call assert_equal('spec', fnamemodify('a.spec.rb', ':e:e:r:r'))
call assert_equal('spec', fnamemodify('a.b.spec.rb', ':e:e:r'))
call assert_equal('b.spec', fnamemodify('a.b.spec.rb', ':e:e:e:r'))
call assert_equal('b', fnamemodify('a.b.spec.rb', ':e:e:e:r:r'))
call assert_equal('spec', fnamemodify('a.b.spec.rb', ':r:e'))
call assert_equal('b', fnamemodify('a.b.spec.rb', ':r:r:e'))
call assert_equal('c', fnamemodify('a.b.c.d.e', ':r:r:e'))
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e'))
" :e never includes the whole filename, so "a.b":e:e:e --> "b"
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e'))
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e:e'))
endfunc

View File

@ -753,6 +753,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2125,
/**/
2124,
/**/