mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.1.0569: fnamemodify() treats ".." and "../" differently
Problem: fnamemodify() treats ".." and "../" differently. Solution: Expand ".." properly like how "/.." is treated in 8.2.3388. (zeertzjq) closes: #15218 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
fc533c9f06
commit
1ee7420460
@@ -2699,6 +2699,9 @@ mch_FullName(
|
||||
if ((force || !mch_isFullName(fname))
|
||||
&& ((p = vim_strrchr(fname, '/')) == NULL || p != fname))
|
||||
{
|
||||
if (p == NULL && STRCMP(fname, "..") == 0)
|
||||
// Handle ".." without path separators.
|
||||
p = fname + 2;
|
||||
/*
|
||||
* If the file name has a path, change to that directory for a moment,
|
||||
* and then get the directory (and get back to where we were).
|
||||
@@ -2707,7 +2710,7 @@ mch_FullName(
|
||||
if (p != NULL)
|
||||
{
|
||||
if (STRCMP(p, "/..") == 0)
|
||||
// for "/path/dir/.." include the "/.."
|
||||
// For "/path/dir/.." include the "/..".
|
||||
p += 3;
|
||||
|
||||
#ifdef HAVE_FCHDIR
|
||||
|
@@ -107,6 +107,9 @@ func Test_findfile()
|
||||
let l = findfile('bar', ';../', -1)
|
||||
call assert_equal(1, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
let l = findfile('bar', ';..', -1)
|
||||
call assert_equal(1, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
|
||||
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2/', -1)
|
||||
call assert_equal(1, len(l))
|
||||
@@ -117,6 +120,9 @@ func Test_findfile()
|
||||
let l = findfile('bar', ';../../', -1)
|
||||
call assert_equal(1, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
let l = findfile('bar', ';../..', -1)
|
||||
call assert_equal(1, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
|
||||
let l = findfile('bar', ';' . save_dir . '/Xfinddir1/', -1)
|
||||
call assert_equal(2, len(l))
|
||||
@@ -130,6 +136,10 @@ func Test_findfile()
|
||||
call assert_equal(2, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
call assert_match('.*/Xfinddir1/bar', l[1])
|
||||
let l = findfile('bar', ';../../..', -1)
|
||||
call assert_equal(2, len(l))
|
||||
call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
|
||||
call assert_match('.*/Xfinddir1/bar', l[1])
|
||||
|
||||
" Test combined downwards and upwards search from Xdir2/.
|
||||
cd ../..
|
||||
|
@@ -14,6 +14,8 @@ func Test_fnamemodify()
|
||||
call assert_equal($HOME .. "/foo" , fnamemodify('~/foo', ':p'))
|
||||
call assert_equal(fnamemodify('.', ':p:h:h:h') .. '/', fnamemodify($HOME .. '/../', ':p'))
|
||||
call assert_equal(fnamemodify('.', ':p:h:h:h') .. '/', fnamemodify($HOME .. '/..', ':p'))
|
||||
call assert_equal(fnamemodify('.', ':p:h:h') .. '/', fnamemodify('../', ':p'))
|
||||
call assert_equal(fnamemodify('.', ':p:h:h') .. '/', fnamemodify('..', ':p'))
|
||||
call assert_equal('test.out', fnamemodify('test.out', ':.'))
|
||||
call assert_equal('a', fnamemodify('../testdir/a', ':.'))
|
||||
call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~'))
|
||||
|
@@ -135,15 +135,15 @@ func Test_tagfiles_stopdir()
|
||||
call writefile([], 'Xtagsdir1/Xtags', 'D')
|
||||
|
||||
cd Xtagsdir1/
|
||||
let &tags = './Xtags;' .. fnamemodify('./..', ':p')
|
||||
let &tags = './Xtags;' .. fnamemodify('..', ':p')
|
||||
call assert_equal(1, len(tagfiles()))
|
||||
|
||||
cd Xtagsdir2/
|
||||
let &tags = './Xtags;' .. fnamemodify('./..', ':p')
|
||||
let &tags = './Xtags;' .. fnamemodify('..', ':p')
|
||||
call assert_equal(1, len(tagfiles()))
|
||||
|
||||
cd Xtagsdir3/
|
||||
let &tags = './Xtags;' .. fnamemodify('./..', ':p')
|
||||
let &tags = './Xtags;' .. fnamemodify('..', ':p')
|
||||
call assert_equal(0, len(tagfiles()))
|
||||
|
||||
let &tags = './Xtags;../'
|
||||
@@ -155,6 +155,15 @@ func Test_tagfiles_stopdir()
|
||||
cd ..
|
||||
call assert_equal(1, len(tagfiles()))
|
||||
|
||||
let &tags = './Xtags;..'
|
||||
call assert_equal(1, len(tagfiles()))
|
||||
|
||||
cd Xtagsdir2/
|
||||
call assert_equal(1, len(tagfiles()))
|
||||
|
||||
cd Xtagsdir3/
|
||||
call assert_equal(0, len(tagfiles()))
|
||||
|
||||
set tags&
|
||||
call chdir(save_cwd)
|
||||
endfunc
|
||||
|
@@ -704,6 +704,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
569,
|
||||
/**/
|
||||
568,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user