Skip to content

Commit

Permalink
process: correctly parse Unicode in NODE_OPTIONS
Browse files Browse the repository at this point in the history
Fixes an issue on Windows, where Unicode in NODE_OPTIONS was not parsed
correctly.

Fixes: nodejs#34399

PR-URL: nodejs#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]>
  • Loading branch information
bzoz committed Aug 20, 2020
1 parent 03293aa commit de565ad
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/node_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,20 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) {

{
Mutex::ScopedLock lock(per_process::env_var_mutex);
if (const char* value = getenv(key)) {
*text = value;

size_t init_sz = 256;
MaybeStackBuffer<char, 256> val;
int ret = uv_os_getenv(key, *val, &init_sz);

if (ret == UV_ENOBUFS) {
// Buffer is not large enough, reallocate to the updated init_sz
// and fetch env value again.
val.AllocateSufficientStorage(init_sz);
ret = uv_os_getenv(key, *val, &init_sz);
}

if (ret >= 0) { // Env key value fetch success.
*text = *val;
return true;
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-unicode-node-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
// Flags: --expose-internals
require('../common');
const { getOptionValue } = require('internal/options');
const assert = require('assert');
const cp = require('child_process');

const expected_redirect_value = 'foó';

if (process.argv.length === 2) {
const NODE_OPTIONS = `--redirect-warnings=${expected_redirect_value}`;
const result = cp.spawnSync(process.argv0,
['--expose-internals', __filename, 'test'],
{
env: {
...process.env,
NODE_OPTIONS
},
stdio: 'inherit'
});
assert.strictEqual(result.status, 0);
} else {
const redirect_value = getOptionValue('--redirect-warnings');
console.log(`--redirect-warings=${redirect_value}`);
assert.strictEqual(redirect_value, expected_redirect_value);
}

0 comments on commit de565ad

Please sign in to comment.