From b67519ebd51f430b7122f222282c218e8b4b90c3 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Thu, 27 Aug 2026 00:54:02 -0600 Subject: [PATCH] fix: preserve parameter expansion (${VAR:-default}) in .env interpolation --- apps/dokploy/__test__/compose/env-file-literals.test.ts | 2 ++ packages/server/src/utils/docker/utils.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/dokploy/__test__/compose/env-file-literals.test.ts b/apps/dokploy/__test__/compose/env-file-literals.test.ts index 91af553a1..b7223ca4a 100644 --- a/apps/dokploy/__test__/compose/env-file-literals.test.ts +++ b/apps/dokploy/__test__/compose/env-file-literals.test.ts @@ -34,6 +34,7 @@ const cases: Record = { MULTILINE_PEM: "-----BEGIN KEY-----\nabc123\n-----END KEY-----", APP_URL: "https://example.com", ASSET_URL: "https://example.com", + DB_HOST: "localhost", }; // How each value must be typed in the UI so the (unchanged) dotenv input @@ -50,6 +51,7 @@ const inputEncoding: Record = { MULTILINE_PEM: '"-----BEGIN KEY-----\nabc123\n-----END KEY-----"', APP_URL: "https://example.com", ASSET_URL: '"${APP_URL}"', + DB_HOST: '"${UNDEFINED_HOST:-localhost}"', }; describe("getCreateEnvFileCommand", () => { diff --git a/packages/server/src/utils/docker/utils.ts b/packages/server/src/utils/docker/utils.ts index e81030f97..e19d7d2fd 100644 --- a/packages/server/src/utils/docker/utils.ts +++ b/packages/server/src/utils/docker/utils.ts @@ -548,7 +548,7 @@ export const prepareEnvironmentVariablesForFile = ( const escapedValue = value .replace(/\\/g, "\\\\") .replace(/"/g, '\\"') - .replace(/\$(?!\{[A-Za-z_][A-Za-z0-9_]*\})/g, "\\$"); + .replace(/\$(?!\{[A-Za-z_][A-Za-z0-9_]*(?::?[-+?][^{}]*)?\})/g, "\\$"); return `${key}="${escapedValue}"`; }); };