mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	exists(): return false for empty env var #10657
Fixes https://github.com/neovim/neovim/issues/3266 close #10657
This commit is contained in:
		 Daniel Hahler
					Daniel Hahler
				
			
				
					committed by
					
						 Justin M. Keyes
						Justin M. Keyes
					
				
			
			
				
	
			
			
			 Justin M. Keyes
						Justin M. Keyes
					
				
			
						parent
						
							5aa97937e7
						
					
				
				
					commit
					06d9cc734b
				
			| @@ -8718,7 +8718,7 @@ static void f_exists(typval_T *argvars, typval_T *rettv, FunPtr fptr) | |||||||
|   const char *p = tv_get_string(&argvars[0]); |   const char *p = tv_get_string(&argvars[0]); | ||||||
|   if (*p == '$') {  // Environment variable. |   if (*p == '$') {  // Environment variable. | ||||||
|     // First try "normal" environment variables (fast). |     // First try "normal" environment variables (fast). | ||||||
|     if (os_getenv(p + 1) != NULL) { |     if (os_env_exists(p + 1)) { | ||||||
|       n = true; |       n = true; | ||||||
|     } else { |     } else { | ||||||
|       // Try expanding things like $VIM and ${HOME}. |       // Try expanding things like $VIM and ${HOME}. | ||||||
|   | |||||||
| @@ -2,11 +2,17 @@ local helpers = require('test.functional.helpers')(after_each) | |||||||
| local clear = helpers.clear | local clear = helpers.clear | ||||||
| local eq = helpers.eq | local eq = helpers.eq | ||||||
| local environ = helpers.funcs.environ | local environ = helpers.funcs.environ | ||||||
|  | local exists = helpers.funcs.exists | ||||||
|  |  | ||||||
| describe('environ()', function() | describe('environment variables', function() | ||||||
|   it('handles empty env variable', function() |   it('environ() handles empty env variable', function() | ||||||
|     clear({env={EMPTY_VAR=""}}) |     clear({env={EMPTY_VAR=""}}) | ||||||
|     eq("", environ()['EMPTY_VAR']) |     eq("", environ()['EMPTY_VAR']) | ||||||
|     eq(nil, environ()['DOES_NOT_EXIST']) |     eq(nil, environ()['DOES_NOT_EXIST']) | ||||||
|   end) |   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) | end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user