Mercurial > vim
changeset 5858:00228400629e v7.4.272
updated for version 7.4.272
Problem: Using just "$" does not cause an error message.
Solution: Check for empty environment variable name. (Christian Brabandt)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 29 Apr 2014 17:41:22 +0200 |
parents | fddd2a7b6ea7 |
children | d528535eadaa |
files | src/eval.c src/testdir/test_eval.in src/testdir/test_eval.ok src/version.c |
diffstat | 4 files changed, 37 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -7798,7 +7798,7 @@ string2float(text, value) * 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. - * Always return OK. + * Return FAIL if the name is invalid. */ static int get_env_tv(arg, rettv, evaluate) @@ -7817,32 +7817,33 @@ get_env_tv(arg, rettv, evaluate) len = get_env_len(arg); if (evaluate) { - if (len != 0) - { - 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} */ - string = expand_env_save(name - 1); - if (string != NULL && *string == '$') - { - vim_free(string); - string = NULL; - } - } - name[len] = cc; - } + 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} */ + string = expand_env_save(name - 1); + if (string != NULL && *string == '$') + { + vim_free(string); + string = NULL; + } + } + name[len] = cc; + rettv->v_type = VAR_STRING; rettv->vval.v_string = string; }
--- a/src/testdir/test_eval.in +++ b/src/testdir/test_eval.in @@ -183,6 +183,13 @@ endfun :" script-local function used in Funcref must exist. :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 :" vim: et ts=4 isk-=\: fmr=???,??? :call getchar()
index f81927bae793f17312ce2f6dad8cf7fba80c8454..313f39eef393647a0c4727c03c1f546a10eaf8e0 GIT binary patch literal 10986 zc%02zOHboS5bm?3xpHo04*`i$Vmr(us~nQp0VFh+8O;T8u!DiDjDr$0GYIW}-+om; z>}nHWc3BSCuCDsN>ULFib&|)&$B>pqP3vM?Z-d^L)(>|D{qZOLk(Kwwm}dEs?w|MB zrGIg7NQ+;0n}$#ueYcGWYDJzhdj}ftTti15Om=g##~yoJEN-~rBcJXp+pd;$ThyE4 zTFsluBPH4IXZ=IUk*55*>>mUfMmJS_Q`b>j984y`gx^nGf?N^I`1J=P$T5PMLYlb* zwipOz4T7a2nDcAN2$tAd&tXmHE`uZI6#SN79ga)Ik?`wx#&L;pB!HE;9FAOZBrT3Y zaisj3Gmb)W?2T-aRAHqqhb@McN*fGUiebU8dyL@<WmqVvh09=zfnm{LxK<3uVh-Vu zaa;pOIJ8NQ722^&VvB*~n2Ns!)s3P$5t9*AH#pUa!aQ-QY%x%spj4-d>XdPuV$pl5 zpiW%|TMP`R6PcIOySt*gTvgX}%l?%GEmu{sr9W5o4e%bgUQ8iVmyoJcG*yKPB&O7N zlNMFb=_>>i4|NGSHpSv!+6q15;7e1)iw<3tCzi04F=j=g9hO9LNp*zLKzaS#$<|#+ z>9`#96-N0!GjC}WI#39ufm<X|1zj$Mz{f3aa+`bas7)?39Rg{KxZziI9THOSibT6C ziGUzdA7M0DJ~wx>Mf?urpm$M)`}xt(UDsjv6r^RBGYb2O={y4mnHt^UZxT=&$X$gw zY{$A*%<=tL=$PGCTQ#<4znb2yg`ia(w63m~b1asCL1?yVGzRL{(?+nw;H8i^JWZgx z$YJYG&}2-AP}0qWwrX@6UM+AYQLiw`T}M)AL9`<&>PSk2l5RP)mD`f|wRDG~97%nS z=pah5AW{tCz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