Merge pull request #5197 from Dokploy/fix/env-file-var-interpolation-5151

fix: preserve ${VAR} interpolation in .env values
This commit is contained in:
Mauricio Siu
2026-08-27 00:54:45 -06:00
committed by GitHub
2 changed files with 7 additions and 1 deletions
@@ -32,6 +32,9 @@ const cases: Record<string, string> = {
APOSTROPHE: "it's a test", APOSTROPHE: "it's a test",
UNICODE: "héllo wörld 日本語 🚀", UNICODE: "héllo wörld 日本語 🚀",
MULTILINE_PEM: "-----BEGIN KEY-----\nabc123\n-----END KEY-----", 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 // How each value must be typed in the UI so the (unchanged) dotenv input
@@ -46,6 +49,9 @@ const inputEncoding: Record<string, string> = {
APOSTROPHE: "it's a test", APOSTROPHE: "it's a test",
UNICODE: "héllo wörld 日本語 🚀", UNICODE: "héllo wörld 日本語 🚀",
MULTILINE_PEM: '"-----BEGIN KEY-----\nabc123\n-----END KEY-----"', MULTILINE_PEM: '"-----BEGIN KEY-----\nabc123\n-----END KEY-----"',
APP_URL: "https://example.com",
ASSET_URL: '"${APP_URL}"',
DB_HOST: '"${UNDEFINED_HOST:-localhost}"',
}; };
describe("getCreateEnvFileCommand", () => { describe("getCreateEnvFileCommand", () => {
+1 -1
View File
@@ -548,7 +548,7 @@ export const prepareEnvironmentVariablesForFile = (
const escapedValue = value const escapedValue = value
.replace(/\\/g, "\\\\") .replace(/\\/g, "\\\\")
.replace(/"/g, '\\"') .replace(/"/g, '\\"')
.replace(/\$/g, "\\$"); .replace(/\$(?!\{[A-Za-z_][A-Za-z0-9_]*(?::?[-+?][^{}]*)?\})/g, "\\$");
return `${key}="${escapedValue}"`; return `${key}="${escapedValue}"`;
}); });
}; };