Skip to content

[Dotenv] Properly handle SYMFONY_DOTENV_VARS being the empty string #52927

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

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/Symfony/Component/Dotenv/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

private function getVariables(array $envFiles): array
{
$vars = explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? '');
$dotenvVars = $_SERVER['SYMFONY_DOTENV_VARS'] ?? '';

if ('' === $dotenvVars) {
return [];
}

$vars = explode(',', $dotenvVars);
sort($vars);

$output = [];
Expand Down
26 changes: 26 additions & 0 deletions src/Symfony/Component/Dotenv/Tests/Command/DebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class DebugCommandTest extends TestCase
*/
public function testErrorOnUninitializedDotenv()
{
unset($_SERVER['SYMFONY_DOTENV_VARS']);

$command = new DebugCommand('dev', __DIR__.'/Fixtures/Scenario1');
$command->setHelperSet(new HelperSet([new FormatterHelper()]));
$tester = new CommandTester($command);
Expand All @@ -34,6 +36,30 @@ public function testErrorOnUninitializedDotenv()
$this->assertStringContainsString('[ERROR] Dotenv component is not initialized', $output);
}

/**
* @runInSeparateProcess
*/
public function testEmptyDotEnvVarsList()
{
$_SERVER['SYMFONY_DOTENV_VARS'] = '';

$command = new DebugCommand('dev', __DIR__.'/Fixtures/Scenario1');
$command->setHelperSet(new HelperSet([new FormatterHelper()]));
$tester = new CommandTester($command);
$tester->execute([]);
$expectedFormat = <<<'OUTPUT'
%a
---------- ------- ------------ ------%S
Variable Value .env.local .env%S
---------- ------- ------------ ------%S

// Note real values might be different between web and CLI.%S
%a
OUTPUT;

$this->assertStringMatchesFormat($expectedFormat, $tester->getDisplay());
}

public function testScenario1InDevEnv()
{
$output = $this->executeCommand(__DIR__.'/Fixtures/Scenario1', 'dev');
Expand Down