mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-30 18:22:49 -04:00 
			
		
		
		
	Merge pull request #1037 from devangels/template_env_1
Fix for invalid environment variable names used on windows that start…
This commit is contained in:
		
						commit
						83345062d7
					
				| @ -64,7 +64,7 @@ func (c Context) Env() map[string]string { | |||||||
| 	envVars := make(map[string]string, len(osEnv)) | 	envVars := make(map[string]string, len(osEnv)) | ||||||
| 	for _, env := range osEnv { | 	for _, env := range osEnv { | ||||||
| 		data := strings.SplitN(env, "=", 2) | 		data := strings.SplitN(env, "=", 2) | ||||||
| 		if len(data) == 2 { | 		if len(data) == 2 && len(data[0]) > 0 { | ||||||
| 			envVars[data[0]] = data[1] | 			envVars[data[0]] = data[1] | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -234,6 +234,9 @@ func TestEnv(t *testing.T) { | |||||||
| 	notExisting := "ENV_TEST_NOT_EXISTING" | 	notExisting := "ENV_TEST_NOT_EXISTING" | ||||||
| 	os.Unsetenv(notExisting) | 	os.Unsetenv(notExisting) | ||||||
| 
 | 
 | ||||||
|  | 	invalidName := "ENV_TEST_INVALID_NAME" | ||||||
|  | 	os.Setenv("="+invalidName, testValue) | ||||||
|  | 
 | ||||||
| 	env := context.Env() | 	env := context.Env() | ||||||
| 	if value := env[name]; value != testValue { | 	if value := env[name]; value != testValue { | ||||||
| 		t.Errorf("Expected env-variable %s value '%s', found '%s'", | 		t.Errorf("Expected env-variable %s value '%s', found '%s'", | ||||||
| @ -244,6 +247,17 @@ func TestEnv(t *testing.T) { | |||||||
| 		t.Errorf("Expected empty env-variable %s, found '%s'", | 		t.Errorf("Expected empty env-variable %s, found '%s'", | ||||||
| 			notExisting, value) | 			notExisting, value) | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	for k, v := range env { | ||||||
|  | 		if strings.Contains(k, invalidName) { | ||||||
|  | 			t.Errorf("Expected invalid name not to be included in Env %s, found in key '%s'", invalidName, k) | ||||||
|  | 		} | ||||||
|  | 		if strings.Contains(v, invalidName) { | ||||||
|  | 			t.Errorf("Expected invalid name not be be included in Env %s, found in value '%s'", invalidName, v) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	os.Unsetenv("=" + invalidName) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestIP(t *testing.T) { | func TestIP(t *testing.T) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user