Skip to content

Commit

Permalink
fix zero length env var (#3496)
Browse files Browse the repository at this point in the history
  • Loading branch information
paperdave authored and Jarred-Sumner committed Jul 3, 2023
1 parent eb33586 commit 975362a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bun.js/bindings/JSEnvironmentVariableMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsGetterEnvironmentVariable, (JSGlobalObject * globalOb
if (UNLIKELY(name.len == 0))
return JSValue::encode(jsUndefined());

if (!Bun__getEnvValue(globalObject, &name, &value) || value.len == 0) {
if (!Bun__getEnvValue(globalObject, &name, &value)) {
return JSValue::encode(jsUndefined());
}

Expand Down Expand Up @@ -144,4 +144,4 @@ JSValue createEnvironmentVariablesMap(Zig::GlobalObject* globalObject)

return object;
}
}
}
10 changes: 10 additions & 0 deletions test/cli/run/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,13 @@ test(".env Windows-style newline (issue #3042)", () => {
const { stdout } = bunRun(`${dir}/index.ts`);
expect(stdout).toBe("|bar\n\nbaz|moo");
});

test(".env with zero length strings", () => {
const dir = tempDirWithFiles("dotenv-issue-zerolength", {
".env": "FOO=''\n",
"index.ts":
"function i(a){return a}\nconsole.log([process.env.FOO,i(process.env).FOO,process.env.FOO.length,i(process.env).FOO.length].join('|'));",
});
const { stdout } = bunRun(`${dir}/index.ts`);
expect(stdout).toBe("||0|0");
});

0 comments on commit 975362a

Please sign in to comment.