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:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user