From 452b7aa2f2a3e18f6ad80bfb185f2380b23d2013 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Thu, 27 Aug 2026 00:47:01 -0600 Subject: [PATCH] fix: preserve ${VAR} interpolation in .env files Escaping in prepareEnvironmentVariablesForFile escaped every $, including inside a deliberate ${VAR} reference, breaking Compose's documented .env variable interpolation. Only escape $ that isn't part of a ${IDENTIFIER} sequence. Fixes #5151 --- apps/dokploy/__test__/compose/env-file-literals.test.ts | 4 ++++ packages/server/src/utils/docker/utils.ts | 2 +- 2 files changed, 5 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 2dbb7fa4e..91af553a1 100644 --- a/apps/dokploy/__test__/compose/env-file-literals.test.ts +++ b/apps/dokploy/__test__/compose/env-file-literals.test.ts @@ -32,6 +32,8 @@ const cases: Record = { APOSTROPHE: "it's a test", UNICODE: "héllo wörld 日本語 🚀", MULTILINE_PEM: "-----BEGIN KEY-----\nabc123\n-----END KEY-----", + APP_URL: "https://example.com", + ASSET_URL: "https://example.com", }; // How each value must be typed in the UI so the (unchanged) dotenv input @@ -46,6 +48,8 @@ const inputEncoding: Record = { APOSTROPHE: "it's a test", UNICODE: "héllo wörld 日本語 🚀", MULTILINE_PEM: '"-----BEGIN KEY-----\nabc123\n-----END KEY-----"', + APP_URL: "https://example.com", + ASSET_URL: '"${APP_URL}"', }; describe("getCreateEnvFileCommand", () => { diff --git a/packages/server/src/utils/docker/utils.ts b/packages/server/src/utils/docker/utils.ts index fccd979fd..e81030f97 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(/\$/g, "\\$"); + .replace(/\$(?!\{[A-Za-z_][A-Za-z0-9_]*\})/g, "\\$"); return `${key}="${escapedValue}"`; }); };