0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

updated for version 7.4.272

Problem:    Using just "$" does not cause an error message.
Solution:   Check for empty environment variable name. (Christian Brabandt)
This commit is contained in:
Bram Moolenaar
2014-04-29 17:41:22 +02:00
parent 121f9bdde4
commit e512c8c049
4 changed files with 35 additions and 25 deletions

View File

@@ -7798,7 +7798,7 @@ string2float(text, value)
* Get the value of an environment variable. * Get the value of an environment variable.
* "arg" is pointing to the '$'. It is advanced to after the name. * "arg" is pointing to the '$'. It is advanced to after the name.
* If the environment variable was not set, silently assume it is empty. * If the environment variable was not set, silently assume it is empty.
* Always return OK. * Return FAIL if the name is invalid.
*/ */
static int static int
get_env_tv(arg, rettv, evaluate) get_env_tv(arg, rettv, evaluate)
@@ -7817,32 +7817,33 @@ get_env_tv(arg, rettv, evaluate)
len = get_env_len(arg); len = get_env_len(arg);
if (evaluate) if (evaluate)
{ {
if (len != 0) if (len == 0)
{ return FAIL; /* can't be an environment variable */
cc = name[len];
name[len] = NUL;
/* first try vim_getenv(), fast for normal environment vars */
string = vim_getenv(name, &mustfree);
if (string != NULL && *string != NUL)
{
if (!mustfree)
string = vim_strsave(string);
}
else
{
if (mustfree)
vim_free(string);
/* next try expanding things like $VIM and ${HOME} */ cc = name[len];
string = expand_env_save(name - 1); name[len] = NUL;
if (string != NULL && *string == '$') /* first try vim_getenv(), fast for normal environment vars */
{ string = vim_getenv(name, &mustfree);
vim_free(string); if (string != NULL && *string != NUL)
string = NULL; {
} if (!mustfree)
} string = vim_strsave(string);
name[len] = cc;
} }
else
{
if (mustfree)
vim_free(string);
/* next try expanding things like $VIM and ${HOME} */
string = expand_env_save(name - 1);
if (string != NULL && *string == '$')
{
vim_free(string);
string = NULL;
}
}
name[len] = cc;
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = string; rettv->vval.v_string = string;
} }

View File

@@ -183,6 +183,13 @@ endfun
:" script-local function used in Funcref must exist. :" script-local function used in Funcref must exist.
:so test_eval_func.vim :so test_eval_func.vim
:" :"
:" Using $ instead of '$' must give an error
:try
: call append($, 'foobar')
:catch
:$put =v:exception
:endtry
:"
:/^start:/+1,$wq! test.out :/^start:/+1,$wq! test.out
:" vim: et ts=4 isk-=\: fmr=???,??? :" vim: et ts=4 isk-=\: fmr=???,???
:call getchar() :call getchar()

Binary file not shown.

View File

@@ -734,6 +734,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 */
/**/
272,
/**/ /**/
271, 271,
/**/ /**/