]> granicus.if.org Git - vim/commitdiff
patch 8.1.2125: fnamemodify() fails when repeating :e v8.1.2125
authorBram Moolenaar <Bram@vim.org>
Tue, 8 Oct 2019 21:26:50 +0000 (23:26 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 8 Oct 2019 21:26:50 +0000 (23:26 +0200)
Problem:    Fnamemodify() fails when repeating :e.
Solution:   Do not go before the tail. (Rob Pilling, closes #5024)

src/filepath.c
src/testdir/test_fnamemodify.vim
src/version.c

index 3a06eec7b382601d4bcd1e57c659c27fdff2a089..cf401dc6d521d2314a92fedb823e2a6b41e6b356 100644 (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;
index fd5f1efb8247f5d40d4925d994a382643fc5ebee..a8324ab8a9e37a6c58ee349fc162ea402d46eeb1 100644 (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
index 514f3c929f54b55059914aea82c903edc168f4f7..a7a7869609d22bbfe572330703175b0c9a0b4d6b 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2125,
 /**/
     2124,
 /**/