Skip to content

Commit 452b7aa

Browse files
committed
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
1 parent 3c6a96a commit 452b7aa

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎apps/dokploy/__test__/compose/env-file-literals.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const cases: Record<string, string> = {
3232
APOSTROPHE: "it's a test",
3333
UNICODE: "héllo wörld 日本語 🚀",
3434
MULTILINE_PEM: "-----BEGIN KEY-----\nabc123\n-----END KEY-----",
35+
APP_URL: "https://example.com",
36+
ASSET_URL: "https://example.com",
3537
};
3638

3739
// How each value must be typed in the UI so the (unchanged) dotenv input
@@ -46,6 +48,8 @@ const inputEncoding: Record<string, string> = {
4648
APOSTROPHE: "it's a test",
4749
UNICODE: "héllo wörld 日本語 🚀",
4850
MULTILINE_PEM: '"-----BEGIN KEY-----\nabc123\n-----END KEY-----"',
51+
APP_URL: "https://example.com",
52+
ASSET_URL: '"${APP_URL}"',
4953
};
5054

5155
describe("getCreateEnvFileCommand", () => {

‎packages/server/src/utils/docker/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ export const prepareEnvironmentVariablesForFile = (
548548
const escapedValue = value
549549
.replace(/\\/g, "\\\\")
550550
.replace(/"/g, '\\"')
551-
.replace(/\$/g, "\\$");
551+
.replace(/\$(?!\{[A-Za-z_][A-Za-z0-9_]*\})/g, "\\$");
552552
return `${key}="${escapedValue}"`;
553553
});
554554
};

0 commit comments

Comments
 (0)