From 235882562388f1339c99ad01f520e7825578bfb4 Mon Sep 17 00:00:00 2001 From: George Ng Date: Wed, 1 Apr 2026 15:54:07 -0700 Subject: [PATCH 1/2] Store trimmed line to avoid trimming twice --- ts/tools/scripts/getKeys.mjs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ts/tools/scripts/getKeys.mjs b/ts/tools/scripts/getKeys.mjs index 0ec9d45dd9..54174ce236 100644 --- a/ts/tools/scripts/getKeys.mjs +++ b/ts/tools/scripts/getKeys.mjs @@ -176,15 +176,21 @@ async function readDotenv() { return []; } const dotenvFile = await fs.promises.readFile(dotenvPath, "utf8"); - const dotEnv = dotenvFile.split("\n").map((line) => { - const [key, ...value] = line.split("="); - if (key.includes("-")) { - throw new Error( - `Invalid dotenv key '${key}' for key vault. Keys cannot contain dashes.`, - ); - } - return [key, value.join("=")]; - }); + const dotEnv = dotenvFile + .split("\n") + .filter((line) => { + const trimmed = line.trim(); + return trimmed !== "" && !trimmed.startsWith("#"); + }) + .map((line) => { + const [key, ...value] = line.split("="); + if (key.includes("-")) { + throw new Error( + `Invalid dotenv key '${key}' for key vault. Keys cannot contain dashes.`, + ); + } + return [key, value.join("=")]; + }); return dotEnv; } From e9b5d3aabe17ac629e7dc5398b8dc8321ac841b0 Mon Sep 17 00:00:00 2001 From: George Ng Date: Thu, 2 Apr 2026 10:34:14 -0700 Subject: [PATCH 2/2] Handle CLRF line endings --- ts/tools/scripts/getKeys.mjs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ts/tools/scripts/getKeys.mjs b/ts/tools/scripts/getKeys.mjs index 54174ce236..659b710b3f 100644 --- a/ts/tools/scripts/getKeys.mjs +++ b/ts/tools/scripts/getKeys.mjs @@ -177,19 +177,20 @@ async function readDotenv() { } const dotenvFile = await fs.promises.readFile(dotenvPath, "utf8"); const dotEnv = dotenvFile - .split("\n") + .split(/\r?\n/) .filter((line) => { const trimmed = line.trim(); return trimmed !== "" && !trimmed.startsWith("#"); }) .map((line) => { const [key, ...value] = line.split("="); - if (key.includes("-")) { + const trimmedKey = key.trim(); + if (trimmedKey.includes("-")) { throw new Error( - `Invalid dotenv key '${key}' for key vault. Keys cannot contain dashes.`, + `Invalid dotenv key '${trimmedKey}' for key vault. Keys cannot contain dashes.`, ); } - return [key, value.join("=")]; + return [trimmedKey, value.join("=").trimEnd()]; }); return dotEnv; }