Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Fix match only APP_KEY in replace #17151

Merged
merged 2 commits into from
Jan 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not read nice to me 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything you would recommend to make it read better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a quick PR: #17226

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and the code review.

}