option: Do not expand options, obtained from XDG vars

It is a wrong thing to do, this makes valid variable values be treated 
incorrectly: in

    XDG_DATA_HOME='/home/$foo/.local/share'

`$foo` should be treated literally and not expanded to `foo` environment 
variable value.

Also makes option_expand not try to expand too long strings even if these too 
long strings are default values. Previously it thought that default values 
should always be expanded. Also does not try to expand NULL should it be the 
default value just in case.

Fixes #4961
This commit is contained in:
ZyX 2016-06-25 23:39:16 +03:00
parent 5573e1a350
commit 895f712df8
4 changed files with 23 additions and 14 deletions

View File

@ -57,9 +57,14 @@ local get_flags = function(o)
add_flag(redraw_flags[r_flag])
end
end
if o.expand then
add_flag('P_EXPAND')
if o.expand == 'nodefault' then
add_flag('P_NO_DEF_EXP')
end
end
for _, flag_desc in ipairs({
{'alloced'},
{'expand'},
{'nodefault'},
{'no_mkrc'},
{'vi_def'},

View File

@ -236,6 +236,7 @@ typedef struct vimoption {
#define P_NO_ML 0x2000000U ///< not allowed in modeline
#define P_CURSWANT 0x4000000U ///< update curswant required; not needed
///< when there is a redraw flag
#define P_NO_DEF_EXP 0x8000000U ///< Do not expand default value.
#define HIGHLIGHT_INIT \
"8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \
@ -726,6 +727,9 @@ void set_init_1(void)
* default.
*/
for (opt_idx = 0; options[opt_idx].fullname; opt_idx++) {
if (options[opt_idx].flags & P_NO_DEF_EXP) {
continue;
}
char *p;
if ((options[opt_idx].flags & P_GETTEXT)
&& options[opt_idx].var != NULL) {
@ -2020,13 +2024,15 @@ static char_u *option_expand(int opt_idx, char_u *val)
if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
return NULL;
/* If val is longer than MAXPATHL no meaningful expansion can be done,
* expand_env() would truncate the string. */
if (val != NULL && STRLEN(val) > MAXPATHL)
return NULL;
if (val == NULL)
if (val == NULL) {
val = *(char_u **)options[opt_idx].var;
}
// If val is longer than MAXPATHL no meaningful expansion can be done,
// expand_env() would truncate the string.
if (val == NULL || STRLEN(val) > MAXPATHL) {
return NULL;
}
/*
* Expanding this with NameBuff, expand_env() must not be passed IObuff.

View File

@ -165,7 +165,7 @@ return {
deny_duplicates=true,
secure=true,
vi_def=true,
expand=true,
expand='nodefault',
varname='p_bdir',
defaults={if_true={vi=''}}
},
@ -616,7 +616,7 @@ return {
deny_duplicates=true,
secure=true,
vi_def=true,
expand=true,
expand='nodefault',
varname='p_dir',
defaults={if_true={vi=''}}
},
@ -1891,7 +1891,7 @@ return {
deny_duplicates=true,
secure=true,
vi_def=true,
expand=true,
expand='nodefault',
varname='p_rtp',
defaults={if_true={vi=''}}
},
@ -2507,7 +2507,7 @@ return {
deny_duplicates=true,
secure=true,
vi_def=true,
expand=true,
expand='nodefault',
varname='p_udir',
defaults={if_true={vi=''}}
},
@ -2568,7 +2568,7 @@ return {
type='string', scope={'global'},
secure=true,
vi_def=true,
expand=true,
expand='nodefault',
varname='p_vdir',
defaults={if_true={vi=''}}
},

View File

@ -76,5 +76,3 @@ describe('startup defaults', function()
end)
end)
end)