mirror of
https://github.com/vim/vim.git
synced 2025-09-29 04:34:16 -04:00
patch 8.1.1091: MS-Windows: cannot use multi-byte chars in environment var
Problem: MS-Windows: cannot use multi-byte chars in environment var. Solution: Use the wide API. (Ken Takata, closes #4008)
This commit is contained in:
91
src/misc1.c
91
src/misc1.c
@@ -4301,41 +4301,46 @@ expand_env_esc(
|
|||||||
char_u *
|
char_u *
|
||||||
vim_getenv(char_u *name, int *mustfree)
|
vim_getenv(char_u *name, int *mustfree)
|
||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p = NULL;
|
||||||
char_u *pend;
|
char_u *pend;
|
||||||
int vimruntime;
|
int vimruntime;
|
||||||
|
#ifdef MSWIN
|
||||||
|
WCHAR *wn, *wp;
|
||||||
|
|
||||||
#if defined(MSWIN)
|
// use "C:/" when $HOME is not set
|
||||||
/* use "C:/" when $HOME is not set */
|
|
||||||
if (STRCMP(name, "HOME") == 0)
|
if (STRCMP(name, "HOME") == 0)
|
||||||
return homedir;
|
return homedir;
|
||||||
#endif
|
|
||||||
|
|
||||||
|
// Use Wide function
|
||||||
|
wn = enc_to_utf16(name, NULL);
|
||||||
|
if (wn == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
wp = _wgetenv(wn);
|
||||||
|
vim_free(wn);
|
||||||
|
|
||||||
|
if (wp != NULL && *wp == NUL) // empty is the same as not set
|
||||||
|
wp = NULL;
|
||||||
|
|
||||||
|
if (wp != NULL)
|
||||||
|
{
|
||||||
|
p = utf16_to_enc(wp, NULL);
|
||||||
|
if (p == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
*mustfree = TRUE;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
#else
|
||||||
p = mch_getenv(name);
|
p = mch_getenv(name);
|
||||||
if (p != NULL && *p == NUL) /* empty is the same as not set */
|
if (p != NULL && *p == NUL) // empty is the same as not set
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
{
|
|
||||||
#if defined(MSWIN)
|
|
||||||
if (enc_utf8)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
char_u *pp = NULL;
|
|
||||||
|
|
||||||
/* Convert from active codepage to UTF-8. Other conversions are
|
|
||||||
* not done, because they would fail for non-ASCII characters. */
|
|
||||||
acp_to_enc(p, (int)STRLEN(p), &pp, &len);
|
|
||||||
if (pp != NULL)
|
|
||||||
{
|
|
||||||
p = pp;
|
|
||||||
*mustfree = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return p;
|
return p;
|
||||||
}
|
#endif
|
||||||
|
|
||||||
|
// handling $VIMRUNTIME and $VIM is below, bail out if it's another name.
|
||||||
vimruntime = (STRCMP(name, "VIMRUNTIME") == 0);
|
vimruntime = (STRCMP(name, "VIMRUNTIME") == 0);
|
||||||
if (!vimruntime && STRCMP(name, "VIM") != 0)
|
if (!vimruntime && STRCMP(name, "VIM") != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -4350,8 +4355,25 @@ vim_getenv(char_u *name, int *mustfree)
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
#ifdef MSWIN
|
||||||
|
// Use Wide function
|
||||||
|
wp = _wgetenv(L"VIM");
|
||||||
|
if (wp != NULL && *wp == NUL) // empty is the same as not set
|
||||||
|
wp = NULL;
|
||||||
|
if (wp != NULL)
|
||||||
|
{
|
||||||
|
char_u *q = utf16_to_enc(wp, NULL);
|
||||||
|
if (q != NULL)
|
||||||
|
{
|
||||||
|
p = vim_version_dir(q);
|
||||||
|
*mustfree = TRUE;
|
||||||
|
if (p == NULL)
|
||||||
|
p = q;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
p = mch_getenv((char_u *)"VIM");
|
p = mch_getenv((char_u *)"VIM");
|
||||||
if (p != NULL && *p == NUL) /* empty is the same as not set */
|
if (p != NULL && *p == NUL) // empty is the same as not set
|
||||||
p = NULL;
|
p = NULL;
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
{
|
{
|
||||||
@@ -4360,27 +4382,8 @@ vim_getenv(char_u *name, int *mustfree)
|
|||||||
*mustfree = TRUE;
|
*mustfree = TRUE;
|
||||||
else
|
else
|
||||||
p = mch_getenv((char_u *)"VIM");
|
p = mch_getenv((char_u *)"VIM");
|
||||||
|
|
||||||
#if defined(MSWIN)
|
|
||||||
if (enc_utf8)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
char_u *pp = NULL;
|
|
||||||
|
|
||||||
/* Convert from active codepage to UTF-8. Other conversions
|
|
||||||
* are not done, because they would fail for non-ASCII
|
|
||||||
* characters. */
|
|
||||||
acp_to_enc(p, (int)STRLEN(p), &pp, &len);
|
|
||||||
if (pp != NULL)
|
|
||||||
{
|
|
||||||
if (*mustfree)
|
|
||||||
vim_free(p);
|
|
||||||
p = pp;
|
|
||||||
*mustfree = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -146,3 +146,8 @@ func Test_let_varg_fail()
|
|||||||
call assert_fails('call s:set_varg8(1)', 'E742:')
|
call assert_fails('call s:set_varg8(1)', 'E742:')
|
||||||
call s:set_varg9([0])
|
call s:set_varg9([0])
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
func Test_let_utf8_environment()
|
||||||
|
let $a = 'ĀĒĪŌŪあいうえお'
|
||||||
|
call assert_equal('ĀĒĪŌŪあいうえお', $a)
|
||||||
|
endfunc
|
||||||
|
@@ -775,6 +775,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 */
|
||||||
|
/**/
|
||||||
|
1091,
|
||||||
/**/
|
/**/
|
||||||
1090,
|
1090,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user