node/test/parallel/test-process-env-symbols.js
cjihrig 1aa595e5bd src: throw on process.env symbol usage
This commit causes process.env to throw when a symbol is used as
either a key or a value.

Fixes: https://github.com/nodejs/node/issues/9429
PR-URL: https://github.com/nodejs/node/pull/9446
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
2016-11-07 11:17:17 -05:00

27 lines
638 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const symbol = Symbol('sym');
const errRegExp = /^TypeError: Cannot convert a Symbol value to a string$/;
// Verify that getting via a symbol key throws.
assert.throws(() => {
process.env[symbol];
}, errRegExp);
// Verify that assigning via a symbol key throws.
assert.throws(() => {
process.env[symbol] = 42;
}, errRegExp);
// Verify that assigning a symbol value throws.
assert.throws(() => {
process.env.foo = symbol;
}, errRegExp);
// Verify that using a symbol with the in operator throws.
assert.throws(() => {
symbol in process.env;
}, errRegExp);