aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/env_loader.zig23
-rw-r--r--test/cli/run/env.test.ts8
2 files changed, 25 insertions, 6 deletions
diff --git a/src/env_loader.zig b/src/env_loader.zig
index 3e2f371a5..bf1bf450e 100644
--- a/src/env_loader.zig
+++ b/src/env_loader.zig
@@ -329,13 +329,24 @@ pub const Loader = struct {
pub fn loadProcess(this: *Loader) void {
if (this.did_load_process) return;
- // This is a little weird because it's evidently stored line-by-line
- var source = logger.Source.initPathString("process.env", "");
-
this.map.map.ensureTotalCapacity(std.os.environ.len) catch unreachable;
- for (std.os.environ) |env| {
- source.contents = bun.span(env);
- Parser.parse(&source, this.allocator, this.map, true, true);
+ for (std.os.environ) |_env| {
+ var env = bun.span(_env);
+ if (strings.indexOfChar(env, '=')) |i| {
+ var key = env[0..i];
+ var value = env[i + 1 ..];
+ if (key.len > 0) {
+ if (value.len > 0) {
+ this.map.put(key, value) catch unreachable;
+ } else {
+ this.map.put(key, empty_string_value) catch unreachable;
+ }
+ }
+ } else {
+ if (env.len > 0) {
+ this.map.put(env, empty_string_value) catch unreachable;
+ }
+ }
}
this.did_load_process = true;
diff --git a/test/cli/run/env.test.ts b/test/cli/run/env.test.ts
index 8ae824607..6e4d83d44 100644
--- a/test/cli/run/env.test.ts
+++ b/test/cli/run/env.test.ts
@@ -230,6 +230,14 @@ test(".env comments", () => {
expect(stdout).toBe("foo bar");
});
+test(".env process variables no comments", () => {
+ const dir = tempDirWithFiles("env-no-comments", {
+ "index.ts": "console.log(process.env.TEST1, process.env.TEST2);",
+ });
+ const { stdout } = bunRun(`${dir}/index.ts`, { TEST1: "test#1", TEST2: '"test#2"' });
+ expect(stdout).toBe('test#1 "test#2"');
+});
+
test(".env escaped dollar sign", () => {
const dir = tempDirWithFiles("dotenv-dollar", {
".env": "FOO=foo\nBAR=\\$FOO",