-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement getenv and putenv in go (#1086)
* implement getenv and putenv in go * fix typo * apply formatting * return a bool * prevent ENV= from crashing * optimization * optimization * split env workflows and use go_strings * clean up unused code * update tests * remove useless sprintf * see if this fixes the asan issues * clean up comments * check that VAR= works correctly and use actual php to validate the behavior * move all unpinning to the end of the request * handle the case where php is not installed * fix copy-paste * optimization * use strings.cut * fix lint * override how env is filled * reuse fullenv * use corect function
- Loading branch information
1 parent
5ec0308
commit e812473
Showing
5 changed files
with
260 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
require_once __DIR__.'/_executor.php'; | ||
|
||
return function() { | ||
$var = 'MY_VAR_' . ($_GET['var'] ?? ''); | ||
// Setting an environment variable | ||
$result = putenv("$var=HelloWorld"); | ||
if ($result) { | ||
echo "Set MY_VAR successfully.\n"; | ||
echo "MY_VAR = " . getenv($var) . "\n"; | ||
} else { | ||
echo "Failed to set MY_VAR.\n"; | ||
} | ||
|
||
// Unsetting the environment variable | ||
$result = putenv($var); | ||
if ($result) { | ||
echo "Unset MY_VAR successfully.\n"; | ||
$value = getenv($var); | ||
if ($value === false) { | ||
echo "MY_VAR is unset.\n"; | ||
} else { | ||
echo "MY_VAR = " . $value . "\n"; | ||
} | ||
} else { | ||
echo "Failed to unset MY_VAR.\n"; | ||
} | ||
|
||
$result = putenv("$var="); | ||
if ($result) { | ||
echo "MY_VAR set to empty successfully.\n"; | ||
$value = getenv($var); | ||
if ($value === false) { | ||
echo "MY_VAR is unset.\n"; | ||
} else { | ||
echo "MY_VAR = " . $value . "\n"; | ||
} | ||
} else { | ||
echo "Failed to set MY_VAR.\n"; | ||
} | ||
|
||
// Attempt to unset a non-existing variable | ||
$result = putenv('NON_EXISTING_VAR' . ($_GET['var'] ?? '')); | ||
if ($result) { | ||
echo "Unset NON_EXISTING_VAR successfully.\n"; | ||
} else { | ||
echo "Failed to unset NON_EXISTING_VAR.\n"; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters