mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
vim-patch:7.4.272
Problem: Using just "$" does not cause an error message. Solution: Check for empty environment variable name. (Christian Brabandt) https://code.google.com/p/vim/source/detail?r=00228400629e28384f7f52556c3c119ba0d0a44d
This commit is contained in:

committed by
Justin M. Keyes

parent
c79d27ee07
commit
5d65e7f279
67
src/eval.c
67
src/eval.c
@@ -6718,45 +6718,50 @@ string2float (
|
|||||||
return (int)((char_u *)s - text);
|
return (int)((char_u *)s - text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// 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.
|
/// 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.
|
/// @param arg Points to the '$'. It is advanced to after the name.
|
||||||
*/
|
/// @return FAIL if the name is invalid.
|
||||||
|
///
|
||||||
static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
|
static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
|
||||||
{
|
{
|
||||||
char_u *string = NULL;
|
char_u *name;
|
||||||
int len;
|
char_u *string = NULL;
|
||||||
int cc;
|
int mustfree = FALSE;
|
||||||
char_u *name;
|
int len;
|
||||||
int mustfree = FALSE;
|
int cc;
|
||||||
|
|
||||||
++*arg;
|
++*arg;
|
||||||
name = *arg;
|
name = *arg;
|
||||||
len = get_env_len(arg);
|
len = get_env_len(arg);
|
||||||
if (evaluate) {
|
|
||||||
if (len != 0) {
|
|
||||||
cc = name[len];
|
|
||||||
name[len] = '\0';
|
|
||||||
/* first try vim_getenv(), fast for normal environment vars */
|
|
||||||
string = vim_getenv(name, &mustfree);
|
|
||||||
if (string != NULL && *string != '\0') {
|
|
||||||
if (!mustfree)
|
|
||||||
string = vim_strsave(string);
|
|
||||||
} else {
|
|
||||||
if (mustfree)
|
|
||||||
vim_free(string);
|
|
||||||
|
|
||||||
/* next try expanding things like $VIM and ${HOME} */
|
if (evaluate) {
|
||||||
string = expand_env_save(name - 1);
|
if (len == 0) {
|
||||||
if (string != NULL && *string == '$') {
|
return FAIL; // Can't be an environment variable.
|
||||||
vim_free(string);
|
|
||||||
string = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
name[len] = cc;
|
|
||||||
}
|
}
|
||||||
|
cc = name[len];
|
||||||
|
name[len] = '\0';
|
||||||
|
// First try vim_getenv(), fast for normal environment vars.
|
||||||
|
string = vim_getenv(name, &mustfree);
|
||||||
|
if (string != NULL && *string != '\0') {
|
||||||
|
if (!mustfree) {
|
||||||
|
string = vim_strsave(string);
|
||||||
|
}
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,14 @@ STARTTEST
|
|||||||
:" 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
|
||||||
|
|
||||||
:$-9,$w! test.out
|
:" using $ instead of '$' must give an error
|
||||||
|
:try
|
||||||
|
: call append($, 'foobar')
|
||||||
|
:catch
|
||||||
|
: $put =v:exception
|
||||||
|
:endtry
|
||||||
|
|
||||||
|
:$-10,$w! test.out
|
||||||
:q!
|
:q!
|
||||||
|
|
||||||
ENDTEST
|
ENDTEST
|
||||||
|
@@ -8,3 +8,4 @@ s:Testje exists: 0
|
|||||||
func s:Testje exists: 1
|
func s:Testje exists: 1
|
||||||
Bar exists: 1
|
Bar exists: 1
|
||||||
func Bar exists: 1
|
func Bar exists: 1
|
||||||
|
Vim(call):E116: Invalid arguments for function append
|
||||||
|
@@ -202,6 +202,9 @@ 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
|
||||||
|
//273,
|
||||||
|
272,
|
||||||
|
//271,
|
||||||
//270,
|
//270,
|
||||||
269,
|
269,
|
||||||
268,
|
268,
|
||||||
|
Reference in New Issue
Block a user