mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(vim.system): clear_env=true gives an invalid env to uv.spawn #33955
Problem:
In setup_env, some needed logic is bypassed when clear_env=true.
Solution:
Drop the early return in setup_env().
Co-authored-by: BirdeeHub <birdee@localhost>
(cherry picked from commit 731e616a79)
			
			
This commit is contained in:
		 Birdee
					Birdee
				
			
				
					committed by
					
						![github-actions[bot]](/assets/img/avatar_default.png) github-actions[bot]
						github-actions[bot]
					
				
			
			
				
	
			
			
			![github-actions[bot]](/assets/img/avatar_default.png) github-actions[bot]
						github-actions[bot]
					
				
			
						parent
						
							68d204462c
						
					
				
				
					commit
					203d4f916d
				
			| @@ -210,15 +210,13 @@ end | |||||||
| --- @param clear_env? boolean | --- @param clear_env? boolean | ||||||
| --- @return string[]? | --- @return string[]? | ||||||
| local function setup_env(env, clear_env) | local function setup_env(env, clear_env) | ||||||
|   if clear_env then |   if not clear_env then | ||||||
|     return env |     --- @type table<string,string|number> | ||||||
|  |     env = vim.tbl_extend('force', base_env(), env or {}) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   --- @type table<string,string|number> |  | ||||||
|   env = vim.tbl_extend('force', base_env(), env or {}) |  | ||||||
|  |  | ||||||
|   local renv = {} --- @type string[] |   local renv = {} --- @type string[] | ||||||
|   for k, v in pairs(env) do |   for k, v in pairs(env or {}) do | ||||||
|     renv[#renv + 1] = string.format('%s=%s', k, tostring(v)) |     renv[#renv + 1] = string.format('%s=%s', k, tostring(v)) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -73,6 +73,26 @@ describe('vim.system', function() | |||||||
|         eq('hellocat', system({ 'cat' }, { stdin = 'hellocat', text = true }).stdout) |         eq('hellocat', system({ 'cat' }, { stdin = 'hellocat', text = true }).stdout) | ||||||
|       end) |       end) | ||||||
|  |  | ||||||
|  |       it('can set environment', function() | ||||||
|  |         eq( | ||||||
|  |           'TESTVAL', | ||||||
|  |           system( | ||||||
|  |             { n.testprg('printenv-test'), 'TEST' }, | ||||||
|  |             { env = { TEST = 'TESTVAL' }, text = true } | ||||||
|  |           ).stdout | ||||||
|  |         ) | ||||||
|  |       end) | ||||||
|  |  | ||||||
|  |       it('can set environment with clear_env = true', function() | ||||||
|  |         eq( | ||||||
|  |           'TESTVAL', | ||||||
|  |           system( | ||||||
|  |             { n.testprg('printenv-test'), 'TEST' }, | ||||||
|  |             { clear_env = true, env = { TEST = 'TESTVAL' }, text = true } | ||||||
|  |           ).stdout | ||||||
|  |         ) | ||||||
|  |       end) | ||||||
|  |  | ||||||
|       it('supports timeout', function() |       it('supports timeout', function() | ||||||
|         eq({ |         eq({ | ||||||
|           code = 124, |           code = 124, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user