mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
src: do not coerce dotenv paths
PR-URL: https://github.com/nodejs/node/pull/51425 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
cf68d006c0
commit
d44814ca68
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user