framework icon indicating copy to clipboard operation
framework copied to clipboard

Regex Pattern in artisan key:generate

Open stephancasas opened this issue 2 years ago • 1 comments

  • Laravel Version: 9.19
  • PHP Version: 8.0.2

Description:

Given the following .env...

APP_NAME=Laravel
APP_KEY=
...

... artisan key:generate will yield...

APP_NAME=Laravel
APP_KEY=base64:133eb1bde70e4ba388bdf74e4ac95cbd=

This includes the trailing = character every time. I don't think it causes an issue, but the output looked strange to me. If the .env file is quoted as APP_KEY="", the command suffixes the ="" chars after the artisan-generated app key. When the APP_KEY string is missing from .env, the key isn't written to the .env file at all.

Is this the intended behavior of the command?


https://github.com/laravel/framework/blob/053840f579cf01d353d81333802afced79b1c0af/src/Illuminate/Foundation/Console/KeyGenerateCommand.php#L98-L124

Steps To Reproduce:

Use a .env formatted similarly to the one below, or omit the APP_KEY string from the .env file entirely, then run php artisan key:generate.

APP_NAME=Laravel
APP_KEY=
...

stephancasas avatar Aug 09 '22 16:08 stephancasas

It serves as padding.

Or check out this marked answer, it explains it quite well.

R3l4x3 avatar Aug 09 '22 23:08 R3l4x3

The padding makes sense, but what caught me off-guard was that it retains the additional characters after the = as well. So if I initially have APP_KEY="", then I get APP_KEY=...="". If the APP_KEY entry is missing from .env entirely, then it isn't written at all.

Is it worth opening a PR for this or is this not something that would be considered an actual bug requiring a fix?

stephancasas avatar Aug 11 '22 02:08 stephancasas

Please don't remove APP_KEY from your env file.

driesvints avatar Aug 11 '22 06:08 driesvints