Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -869,11 +869,9 @@ static ExitCode InitializeNodeWithArgsInternal(

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

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

if (!path_exists) errors->push_back(file_path + ": not found");
}
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-dotenv-edge-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const common = require('../common');
const assert = require('node:assert');
const path = require('node:path');
const { describe, it } = require('node:test');

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

it('supports absolute paths', async () => {
const code = `
require('assert').strictEqual(process.env.BASIC, 'basic');
`.trim();
const child = await common.spawnPromisified(
process.execPath,
[ `--env-file=${path.resolve(__dirname, validEnvFilePath)}`, '--eval', code ],
);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});

it('should handle non-existent .env file', async () => {
const code = `
require('assert').strictEqual(1, 1)
Expand Down