mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.1.2234: get_short_pathname() fails depending on encoding
Problem: get_short_pathname() fails depending on encoding. Solution: Use the wide version of the library function. (closes #5129)
This commit is contained in:
parent
69bf634858
commit
3f39697b73
@ -30,26 +30,56 @@
|
|||||||
get_short_pathname(char_u **fnamep, char_u **bufp, int *fnamelen)
|
get_short_pathname(char_u **fnamep, char_u **bufp, int *fnamelen)
|
||||||
{
|
{
|
||||||
int l, len;
|
int l, len;
|
||||||
char_u *newbuf;
|
WCHAR *newbuf;
|
||||||
|
WCHAR *wfname;
|
||||||
|
|
||||||
len = *fnamelen;
|
len = MAXPATHL;
|
||||||
l = GetShortPathName((LPSTR)*fnamep, (LPSTR)*fnamep, len);
|
newbuf = malloc(len * sizeof(*newbuf));
|
||||||
|
if (newbuf == NULL)
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
|
wfname = enc_to_utf16(*fnamep, NULL);
|
||||||
|
if (wfname == NULL)
|
||||||
|
{
|
||||||
|
vim_free(newbuf);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
l = GetShortPathNameW(wfname, newbuf, len);
|
||||||
if (l > len - 1)
|
if (l > len - 1)
|
||||||
{
|
{
|
||||||
// If that doesn't work (not enough space), then save the string
|
// If that doesn't work (not enough space), then save the string
|
||||||
// and try again with a new buffer big enough.
|
// and try again with a new buffer big enough.
|
||||||
newbuf = vim_strnsave(*fnamep, l);
|
WCHAR *newbuf_t = newbuf;
|
||||||
|
newbuf = vim_realloc(newbuf, (l + 1) * sizeof(*newbuf));
|
||||||
if (newbuf == NULL)
|
if (newbuf == NULL)
|
||||||
|
{
|
||||||
|
vim_free(wfname);
|
||||||
|
vim_free(newbuf_t);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
}
|
||||||
vim_free(*bufp);
|
|
||||||
*fnamep = *bufp = newbuf;
|
|
||||||
|
|
||||||
// Really should always succeed, as the buffer is big enough.
|
// Really should always succeed, as the buffer is big enough.
|
||||||
l = GetShortPathName((LPSTR)*fnamep, (LPSTR)*fnamep, l+1);
|
l = GetShortPathNameW(wfname, newbuf, l+1);
|
||||||
}
|
}
|
||||||
|
if (l != 0)
|
||||||
|
{
|
||||||
|
char_u *p = utf16_to_enc(newbuf, NULL);
|
||||||
|
if (p != NULL)
|
||||||
|
{
|
||||||
|
vim_free(*bufp);
|
||||||
|
*fnamep = *bufp = p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vim_free(wfname);
|
||||||
|
vim_free(newbuf);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vim_free(wfname);
|
||||||
|
vim_free(newbuf);
|
||||||
|
|
||||||
*fnamelen = l;
|
*fnamelen = l == 0 ? l : STRLEN(*bufp);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
" Test for shortpathname ':8' extension.
|
" Test for shortpathname ':8' extension.
|
||||||
" Only for use on Win32 systems!
|
" Only for use on Win32 systems!
|
||||||
|
|
||||||
|
set encoding=utf-8
|
||||||
|
scriptencoding utf-8
|
||||||
|
|
||||||
source check.vim
|
source check.vim
|
||||||
CheckMSWindows
|
CheckMSWindows
|
||||||
|
|
||||||
@ -67,3 +70,20 @@ func Test_ColonEight()
|
|||||||
|
|
||||||
exe "cd " . save_dir
|
exe "cd " . save_dir
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_ColonEight_MultiByte()
|
||||||
|
let dir = 'Xtest'
|
||||||
|
|
||||||
|
let file = dir . '/日本語のファイル.txt'
|
||||||
|
|
||||||
|
call mkdir(dir)
|
||||||
|
call writefile([], file)
|
||||||
|
|
||||||
|
let sfile = fnamemodify(file, ':8')
|
||||||
|
|
||||||
|
call assert_notequal(file, sfile)
|
||||||
|
call assert_match('\~', sfile)
|
||||||
|
|
||||||
|
call delete(file)
|
||||||
|
call delete(dir, 'd')
|
||||||
|
endfunc
|
||||||
|
@ -741,6 +741,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2234,
|
||||||
/**/
|
/**/
|
||||||
2233,
|
2233,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user