Skip to content

Commit 53eae0d

Browse files
bzozaddaleax
authored andcommitted
process: correctly parse Unicode in NODE_OPTIONS
Fixes an issue on Windows, where Unicode in NODE_OPTIONS was not parsed correctly. Fixes: #34399 PR-URL: #34476 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Denys Otrishko <[email protected]>
1 parent 9d52480 commit 53eae0d

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/node_credentials.cc

+14-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,20 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) {
5858

5959
{
6060
Mutex::ScopedLock lock(per_process::env_var_mutex);
61-
if (const char* value = getenv(key)) {
62-
*text = value;
61+
62+
size_t init_sz = 256;
63+
MaybeStackBuffer<char, 256> val;
64+
int ret = uv_os_getenv(key, *val, &init_sz);
65+
66+
if (ret == UV_ENOBUFS) {
67+
// Buffer is not large enough, reallocate to the updated init_sz
68+
// and fetch env value again.
69+
val.AllocateSufficientStorage(init_sz);
70+
ret = uv_os_getenv(key, *val, &init_sz);
71+
}
72+
73+
if (ret >= 0) { // Env key value fetch success.
74+
*text = *val;
6375
return true;
6476
}
6577
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
// Flags: --expose-internals
3+
require('../common');
4+
const { getOptionValue } = require('internal/options');
5+
const assert = require('assert');
6+
const cp = require('child_process');
7+
8+
const expected_redirect_value = 'foó';
9+
10+
if (process.argv.length === 2) {
11+
const NODE_OPTIONS = `--redirect-warnings=${expected_redirect_value}`;
12+
const result = cp.spawnSync(process.argv0,
13+
['--expose-internals', __filename, 'test'],
14+
{
15+
env: {
16+
...process.env,
17+
NODE_OPTIONS
18+
},
19+
stdio: 'inherit'
20+
});
21+
assert.strictEqual(result.status, 0);
22+
} else {
23+
const redirect_value = getOptionValue('--redirect-warnings');
24+
console.log(`--redirect-warings=${redirect_value}`);
25+
assert.strictEqual(redirect_value, expected_redirect_value);
26+
}

0 commit comments

Comments
 (0)