This commit is contained in:
Alliballibaba
2025-12-12 14:03:28 +01:00
parent c578745f3e
commit 75a07f8834
5 changed files with 12 additions and 9 deletions

View File

@@ -23,8 +23,10 @@ var testPort = "9080"
func TestMain(m *testing.M) {
// setup custom environment vars for TestOsEnv
os.Setenv("ENV1", "value1")
os.Setenv("ENV2", "value2")
if os.Setenv("ENV1", "value1") != nil || os.Setenv("ENV2", "value2") != nil {
fmt.Println("Failed to set environment variables for tests")
os.Exit(1)
}
os.Exit(m.Run())
}

5
env.go
View File

@@ -13,8 +13,7 @@ import (
//export go_init_os_env
func go_init_os_env(mainThreadEnv *C.zend_array) {
env := os.Environ()
for _, envVar := range env {
for _, envVar := range os.Environ() {
key, val, _ := strings.Cut(envVar, "=")
zkey := C.frankenphp_init_persistent_string(toUnsafeChar(key), C.size_t(len(key)))
zvalStr := C.frankenphp_init_persistent_string(toUnsafeChar(val), C.size_t(len(val)))
@@ -31,7 +30,7 @@ func go_putenv(name *C.char, nameLen C.int, val *C.char, valLen C.int) C.bool {
goName := C.GoStringN(name, nameLen)
if val == nil {
// If no "=" is present in putenv(...), unset the environment variable
// If no "=" is present, unset the environment variable
return C.bool(os.Unsetenv(goName) == nil)
}

View File

@@ -1071,7 +1071,7 @@ int frankenphp_execute_script(char *file_name) {
zend_destroy_file_handle(&file_handle);
/* Reset values added through putenv() */
/* Reset values the sandboxed environment */
if (sandboxed_env != NULL) {
zend_hash_release(sandboxed_env);
sandboxed_env = NULL;

View File

@@ -148,7 +148,10 @@ func TestMain(m *testing.M) {
}
// setup custom environment var for TestWorkerHasOSEnvironmentVariableInSERVER
os.Setenv("CUSTOM_OS_ENV_VARIABLE", "custom_env_variable_value")
if os.Setenv("CUSTOM_OS_ENV_VARIABLE", "custom_env_variable_value") != nil {
fmt.Println("Failed to set environment variable for tests")
os.Exit(1)
}
os.Exit(m.Run())
}

View File

@@ -58,8 +58,7 @@ return function() {
// Inserting an invalid variable should fail (null byte in key)
putenv("INVALID\x0_VAR=value");
$value = getenv("INVALID\x0_VAR");
if ($value) {
if (getenv("INVALID\x0_VAR")) {
echo "Invalid value was inserted (unexpected).\n";
} else {
echo "Invalid value was not inserted.\n";