Skip to content

Commit b707147

Browse files
committed
Better handling of values that may need to be wrapped in quotes within the environment file, closes pterodactyl#2304
1 parent 6ac12fc commit b707147

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

app/Traits/Commands/EnvironmentWriterTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public function writeToEnvironment(array $values = [])
3030
$saveContents = file_get_contents($path);
3131
collect($values)->each(function ($value, $key) use (&$saveContents) {
3232
$key = strtoupper($key);
33-
if (str_contains($value, ' ') && ! preg_match('/\"(.*)\"/', $value)) {
33+
// If the key value is not sorrounded by quotation marks, and contains anything that could reasonably
34+
// cause environment parsing issues, wrap it in quotes before writing it. This also adds slashes to the
35+
// value to ensure quotes within it don't cause us issues.
36+
if (! preg_match('/^\"(.*)\"$/', $value) && preg_match('/([^\w.\-+\/])+/', $value)) {
3437
$value = sprintf('"%s"', addslashes($value));
3538
}
3639

0 commit comments

Comments
 (0)