fix(env): prevent crash on single-character .env values

A value like `X=a` would pass the startsWith/endsWith quote check
(both `"` and `'` are single chars), then slice(1, -1) would produce
an empty string, silently dropping the value. Add length >= 2 guard
before checking for surrounding quotes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-03-26 19:01:17 -03:00
parent 4383e3e61a
commit 0f01fe2c07

View File

@@ -30,8 +30,9 @@ export function readEnvFile(keys: string[]): Record<string, string> {
if (!wanted.has(key)) continue; if (!wanted.has(key)) continue;
let value = trimmed.slice(eqIdx + 1).trim(); let value = trimmed.slice(eqIdx + 1).trim();
if ( if (
(value.startsWith('"') && value.endsWith('"')) || value.length >= 2 &&
(value.startsWith("'") && value.endsWith("'")) ((value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'")))
) { ) {
value = value.slice(1, -1); value = value.slice(1, -1);
} }