Skip to content

Commit 2a92196

Browse files
tniessenrichardlau
authored andcommitted
src: do not coerce dotenv paths
PR-URL: #51425 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 292d017 commit 2a92196

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/node.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,9 @@ static ExitCode InitializeNodeWithArgsInternal(
865865

866866
if (!file_paths.empty()) {
867867
CHECK(!per_process::v8_initialized);
868-
auto cwd = Environment::GetCwd(Environment::GetExecPath(*argv));
869868

870869
for (const auto& file_path : file_paths) {
871-
std::string path = cwd + kPathSeparator + file_path;
872-
auto path_exists = per_process::dotenv_file.ParsePath(path);
870+
bool path_exists = per_process::dotenv_file.ParsePath(file_path);
873871

874872
if (!path_exists) errors->push_back(file_path + ": not found");
875873
}

test/parallel/test-dotenv-edge-cases.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const common = require('../common');
44
const assert = require('node:assert');
5+
const path = require('node:path');
56
const { describe, it } = require('node:test');
67

78
const validEnvFilePath = '../fixtures/dotenv/valid.env';
@@ -25,6 +26,18 @@ describe('.env supports edge cases', () => {
2526
assert.strictEqual(child.code, 0);
2627
});
2728

29+
it('supports absolute paths', async () => {
30+
const code = `
31+
require('assert').strictEqual(process.env.BASIC, 'basic');
32+
`.trim();
33+
const child = await common.spawnPromisified(
34+
process.execPath,
35+
[ `--env-file=${path.resolve(__dirname, validEnvFilePath)}`, '--eval', code ],
36+
);
37+
assert.strictEqual(child.stderr, '');
38+
assert.strictEqual(child.code, 0);
39+
});
40+
2841
it('should handle non-existent .env file', async () => {
2942
const code = `
3043
require('assert').strictEqual(1, 1)

0 commit comments

Comments
 (0)