aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-07-30 11:37:39 +0200
committerJustin M. Keyes <justinkz@gmail.com>2019-08-09 23:42:03 +0200
commit06d9cc734bf0397b365d5d75b1766a4fb245d2f5 (patch)
treeb069e48cb909ac895c3952cf953a4b379cb885b5
parent5aa97937e7844f2d3d5e1b015e6749d1f2955697 (diff)
downloadrneovim-06d9cc734bf0397b365d5d75b1766a4fb245d2f5.tar.gz
rneovim-06d9cc734bf0397b365d5d75b1766a4fb245d2f5.tar.bz2
rneovim-06d9cc734bf0397b365d5d75b1766a4fb245d2f5.zip
exists(): return false for empty env var #10657
Fixes https://github.com/neovim/neovim/issues/3266 close #10657
-rw-r--r--src/nvim/eval.c2
-rw-r--r--test/functional/eval/environ_spec.lua10
2 files changed, 9 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 31a49faaf3..1d221bb600 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -8718,7 +8718,7 @@ static void f_exists(typval_T *argvars, typval_T *rettv, FunPtr fptr)
const char *p = tv_get_string(&argvars[0]);
if (*p == '$') { // Environment variable.
// First try "normal" environment variables (fast).
- if (os_getenv(p + 1) != NULL) {
+ if (os_env_exists(p + 1)) {
n = true;
} else {
// Try expanding things like $VIM and ${HOME}.
diff --git a/test/functional/eval/environ_spec.lua b/test/functional/eval/environ_spec.lua
index eb52f9e2da..4c2adcf1bf 100644
--- a/test/functional/eval/environ_spec.lua
+++ b/test/functional/eval/environ_spec.lua
@@ -2,11 +2,17 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local environ = helpers.funcs.environ
+local exists = helpers.funcs.exists
-describe('environ()', function()
- it('handles empty env variable', function()
+describe('environment variables', function()
+ it('environ() handles empty env variable', function()
clear({env={EMPTY_VAR=""}})
eq("", environ()['EMPTY_VAR'])
eq(nil, environ()['DOES_NOT_EXIST'])
end)
+ it('exists() handles empty env variable', function()
+ clear({env={EMPTY_VAR=""}})
+ eq(1, exists('$EMPTY_VAR'))
+ eq(0, exists('$DOES_NOT_EXIST'))
+ end)
end)