Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(upgrade): ignore whitespace around root user values before quoting

Andras Bacsai7faa46bbd436
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 = "[email protected]\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);