Skip to content

Commit 4e93602

Browse files
fix(cli): service.env updates only open a quoted span where parseEnv does
trimStart() skipped Unicode whitespace such as NBSP that util.parseEnv keeps in an unquoted value, so the updater invented a multiline span and dropped the entries inside it. Skip only spaces, tabs and CRs, as parseEnv does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8e4ba36 commit 4e93602

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎apps/server/src/cli/service.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export const upsertServiceEnv = (
5454
const match = SERVICE_ENV_KEY.exec(line);
5555
let end = index + 1;
5656
if (match !== null) {
57-
// util.parseEnv lets a quoted value run to its closing quote across lines.
58-
const rest = line.slice(match[0].length).trimStart();
57+
// util.parseEnv lets a quoted value run to its closing quote across lines,
58+
// skipping only spaces, tabs and CRs before the opening quote.
59+
const rest = line.slice(match[0].length).replace(/^[ \t\r]+/u, "");
5960
const quote = rest[0];
6061
if ((quote === '"' || quote === "'" || quote === "`") && !rest.includes(quote, 1)) {
6162
const closing = contents.indexOf(quote, offset + line.length);

‎apps/server/src/cli/up.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ it("rewrites only the named service.env keys and keeps the user's lines", () =>
418418
T3CODE_LAN: "false",
419419
}),
420420
).toBe('T3CODE_LAN=false\nCUSTOM="x\nT3CODE_LAN=y"\n');
421+
expect(
422+
upsertServiceEnv('T3CODE_LAN=\u00a0"unused\nCUSTOM=keep\nEND="\nT3CODE_LAN=true\n', {
423+
T3CODE_LAN: "false",
424+
}),
425+
).toBe('T3CODE_LAN=false\nCUSTOM=keep\nEND="\n');
421426
const long = `CUSTOM="${"\n".repeat(130_000)}"\n`;
422427
expect(upsertServiceEnv(`${long}T3CODE_LAN=true\n`, { T3CODE_LAN: "false" })).toBe(
423428
`${long}T3CODE_LAN=false\n`,

0 commit comments

Comments
 (0)