aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/JSEnvironmentVariableMap.cpp4
-rw-r--r--test/cli/run/env.test.ts10
2 files changed, 12 insertions, 2 deletions
diff --git a/src/bun.js/bindings/JSEnvironmentVariableMap.cpp b/src/bun.js/bindings/JSEnvironmentVariableMap.cpp
index 5c0357066..4989f7e96 100644
--- a/src/bun.js/bindings/JSEnvironmentVariableMap.cpp
+++ b/src/bun.js/bindings/JSEnvironmentVariableMap.cpp
@@ -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());
}
@@ -144,4 +144,4 @@ JSValue createEnvironmentVariablesMap(Zig::GlobalObject* globalObject)
return object;
}
-} \ No newline at end of file
+}
diff --git a/test/cli/run/env.test.ts b/test/cli/run/env.test.ts
index 0cab610a5..e6ee99dd2 100644
--- a/test/cli/run/env.test.ts
+++ b/test/cli/run/env.test.ts
@@ -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");
+});