From bafd2c423dca3b88d721b55f2f7f83acc4591321 Mon Sep 17 00:00:00 2001 From: Theo Kouzelis Date: Wed, 4 Jan 2017 23:52:59 +0000 Subject: [PATCH 1/2] Fix issue #17140 match only APP_KEY in replace Changed str_replace to preg_replace to ensure no clashes with other environment variables --- .../Foundation/Console/KeyGenerateCommand.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Console/KeyGenerateCommand.php b/src/Illuminate/Foundation/Console/KeyGenerateCommand.php index f30fffb81d79..0eb0e4cfc464 100644 --- a/src/Illuminate/Foundation/Console/KeyGenerateCommand.php +++ b/src/Illuminate/Foundation/Console/KeyGenerateCommand.php @@ -51,8 +51,8 @@ public function fire() */ protected function setKeyInEnvironmentFile($key) { - file_put_contents($this->laravel->environmentFilePath(), str_replace( - 'APP_KEY='.$this->laravel['config']['app.key'], + file_put_contents($this->laravel->environmentFilePath(), preg_replace( + $this->getAppKeyPattern(), 'APP_KEY='.$key, file_get_contents($this->laravel->environmentFilePath()) )); @@ -69,4 +69,16 @@ protected function generateRandomKey() $this->laravel['config']['app.cipher'] == 'AES-128-CBC' ? 16 : 32 )); } + + /** + * Get a regex pattern that will match env APP_KEY with any random key + * + * @return string + */ + protected function getAppKeyPattern() + { + $escapedKey = preg_quote('='.$this->laravel['config']['app.key'], '/'); + + return "/^APP_KEY$escapedKey/m"; + } } From 53cc6285fa78a666641361dc03d5de643defeb00 Mon Sep 17 00:00:00 2001 From: Theo Kouzelis Date: Thu, 5 Jan 2017 00:02:46 +0000 Subject: [PATCH 2/2] CI failure fix --- src/Illuminate/Foundation/Console/KeyGenerateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/KeyGenerateCommand.php b/src/Illuminate/Foundation/Console/KeyGenerateCommand.php index 0eb0e4cfc464..3c8fea526cb6 100644 --- a/src/Illuminate/Foundation/Console/KeyGenerateCommand.php +++ b/src/Illuminate/Foundation/Console/KeyGenerateCommand.php @@ -71,7 +71,7 @@ protected function generateRandomKey() } /** - * Get a regex pattern that will match env APP_KEY with any random key + * Get a regex pattern that will match env APP_KEY with any random key. * * @return string */