From 7faa46bbd436f87e4b39c5ef5134d530d205d843 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:28:14 +0100 Subject: [PATCH] fix(upgrade): ignore whitespace around root user values before quoting phpdotenv trims whitespace around an unquoted value, including the \r of CRLF line endings. The repair quoted such values, which broke valid lines in CRLF files and kept spaces that phpdotenv drops. Trim the value first and quote it only when a space is still inside it. Closes #12375 Co-Authored-By: Claude Opus 5.5 --- other/nightly/upgrade.sh | 3 +++ scripts/upgrade.sh | 3 +++ tests/Unit/UpgradeScriptRootUserEnvTest.php | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/other/nightly/upgrade.sh b/other/nightly/upgrade.sh index 35c087db69..fea3c360c7 100644 --- a/other/nightly/upgrade.sh +++ b/other/nightly/upgrade.sh @@ -228,6 +228,9 @@ quote_root_user_env_values() { local key value for key in ROOT_USERNAME ROOT_USER_EMAIL ROOT_USER_PASSWORD; do value=$(grep -m1 "^${key}=" "$ENV_FILE" | cut -d '=' -f2-) || continue + # phpdotenv ignores whitespace around an unquoted value (also the \r of CRLF line endings) + value="${value#"${value%%[![:space:]]*}"}" + value="${value%"${value##*[![:space:]]}"}" case "$value" in \"* | \'* | *[[:space:]]\#*) continue ;; *[[:space:]]*) ;; diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index 9377d79c5a..e39f6378e7 100644 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -228,6 +228,9 @@ quote_root_user_env_values() { local key value for key in ROOT_USERNAME ROOT_USER_EMAIL ROOT_USER_PASSWORD; do value=$(grep -m1 "^${key}=" "$ENV_FILE" | cut -d '=' -f2-) || continue + # phpdotenv ignores whitespace around an unquoted value (also the \r of CRLF line endings) + value="${value#"${value%%[![:space:]]*}"}" + value="${value%"${value##*[![:space:]]}"}" case "$value" in \"* | \'* | *[[:space:]]\#*) continue ;; *[[:space:]]*) ;; diff --git a/tests/Unit/UpgradeScriptRootUserEnvTest.php b/tests/Unit/UpgradeScriptRootUserEnvTest.php index e77ea3f6a2..6829e17155 100644 --- a/tests/Unit/UpgradeScriptRootUserEnvTest.php +++ b/tests/Unit/UpgradeScriptRootUserEnvTest.php @@ -65,3 +65,15 @@ it('keeps root user credentials that already parse unchanged', function (string expect(repairRootUserEnvWithUpgradeScript($scriptPath, $initialEnv))->toBe($initialEnv); })->with($upgradeScripts); + +it('keeps root user credentials that only have whitespace around the value unchanged', function (string $scriptPath) { + $initialEnv = "ROOT_USER_EMAIL=admin@example.com\r\nROOT_USERNAME= Jane\r\nROOT_USER_PASSWORD=Secret1! \r\nAPP_ENV=production\r\n"; + + expect(repairRootUserEnvWithUpgradeScript($scriptPath, $initialEnv))->toBe($initialEnv); +})->with($upgradeScripts); + +it('quotes a root username with spaces in a file with CRLF line endings', function (string $scriptPath) { + $env = repairRootUserEnvWithUpgradeScript($scriptPath, "ROOT_USERNAME=Jane Doe\r\nAPP_ENV=production\r\n"); + + expect(Dotenv::parse($env))->toBe(['ROOT_USERNAME' => 'Jane Doe', 'APP_ENV' => 'production']); +})->with($upgradeScripts);