diff --git a/dotenv/mod.ts b/dotenv/mod.ts index fd49e594c970..417e909d0a6c 100644 --- a/dotenv/mod.ts +++ b/dotenv/mod.ts @@ -76,9 +76,9 @@ export function loadSync( if (defaultsPath) { const confDefaults = parseFileSync(defaultsPath); - for (const key in confDefaults) { + for (const [key, value] of Object.entries(confDefaults)) { if (!(key in conf)) { - conf[key] = confDefaults[key]; + conf[key] = value; } } } @@ -89,9 +89,9 @@ export function loadSync( } if (_export) { - for (const key in conf) { + for (const [key, value] of Object.entries(conf)) { if (Deno.env.get(key) !== undefined) continue; - Deno.env.set(key, conf[key]); + Deno.env.set(key, value); } } @@ -283,9 +283,9 @@ export async function load( if (defaultsPath) { const confDefaults = await parseFile(defaultsPath); - for (const key in confDefaults) { + for (const [key, value] of Object.entries(confDefaults)) { if (!(key in conf)) { - conf[key] = confDefaults[key]; + conf[key] = value; } } } @@ -296,9 +296,9 @@ export async function load( } if (_export) { - for (const key in conf) { + for (const [key, value] of Object.entries(conf)) { if (Deno.env.get(key) !== undefined) continue; - Deno.env.set(key, conf[key]); + Deno.env.set(key, value); } } diff --git a/dotenv/parse.ts b/dotenv/parse.ts index 241abeea096d..03e226386bee 100644 --- a/dotenv/parse.ts +++ b/dotenv/parse.ts @@ -24,7 +24,7 @@ function expandCharacters(str: string): string { return str.replace( /\\([nrt])/g, - ($1: keyof CharactersMap): string => charactersMap[$1], + ($1: keyof CharactersMap): string => charactersMap[$1] || "", ); } @@ -89,7 +89,7 @@ export function parse(rawDotenv: string): Record { //https://github.com/motdotla/dotenv-expand/blob/ed5fea5bf517a09fd743ce2c63150e88c8a5f6d1/lib/main.js#L23 const variablesMap = { ...env }; keysForExpandCheck.forEach((key) => { - env[key] = expand(env[key], variablesMap); + env[key] = expand(env[key]!, variablesMap); }); return env; diff --git a/dotenv/parse_test.ts b/dotenv/parse_test.ts index 342b8b9dee4e..a3a5536556df 100644 --- a/dotenv/parse_test.ts +++ b/dotenv/parse_test.ts @@ -50,7 +50,7 @@ Deno.test("parse()", () => { ); assertEquals( - JSON.parse(load.JSON).foo, + JSON.parse(load.JSON || JSON.stringify({})).foo, "bar", "inner quotes are maintained", );