Skip to content

Commit

Permalink
Fix issue #17140 match only APP_KEY in replace
Browse files Browse the repository at this point in the history
Changed str_replace to preg_replace to ensure no clashes with other
environment variables
  • Loading branch information
TheoKouzelis committed Jan 4, 2017
1 parent d75cafc commit bafd2c4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Illuminate/Foundation/Console/KeyGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
));
Expand All @@ -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";
}
}

0 comments on commit bafd2c4

Please sign in to comment.