From b707147b73f0adeb35ab39f53008d02d689aff86 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 1 Sep 2020 19:45:24 -0700 Subject: [PATCH] Better handling of values that may need to be wrapped in quotes within the environment file, closes #2304 --- app/Traits/Commands/EnvironmentWriterTrait.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Traits/Commands/EnvironmentWriterTrait.php b/app/Traits/Commands/EnvironmentWriterTrait.php index bc4d2486e..6726e931f 100644 --- a/app/Traits/Commands/EnvironmentWriterTrait.php +++ b/app/Traits/Commands/EnvironmentWriterTrait.php @@ -30,7 +30,10 @@ trait EnvironmentWriterTrait $saveContents = file_get_contents($path); collect($values)->each(function ($value, $key) use (&$saveContents) { $key = strtoupper($key); - if (str_contains($value, ' ') && ! preg_match('/\"(.*)\"/', $value)) { + // If the key value is not sorrounded by quotation marks, and contains anything that could reasonably + // cause environment parsing issues, wrap it in quotes before writing it. This also adds slashes to the + // value to ensure quotes within it don't cause us issues. + if (! preg_match('/^\"(.*)\"$/', $value) && preg_match('/([^\w.\-+\/])+/', $value)) { $value = sprintf('"%s"', addslashes($value)); }