diff --git a/lib/internal/process.js b/lib/internal/process.js index 3de3ae1603deb5..d6a4b6c4fcd97e 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -128,11 +128,22 @@ function setupConfig(_source) { // strip the gyp comment line at the beginning config = config.split('\n') .slice(1) - .join('\n') - .replace(/"/g, '\\"') - .replace(/'/g, '"'); + .join('\n'); + + // convert the Python syntax to proper JSON + // We cannot use a regex due to side effects on static properties of RegExp + // (e.g., RegExp.$_). + let out = ''; + for (const ch of config) { + if (ch === '"') + out += '\\"'; + else if (ch === "'") + out += '"'; + else + out += ch; + } - process.config = JSON.parse(config, function(key, value) { + process.config = JSON.parse(out, function(key, value) { if (value === 'true') return true; if (value === 'false') return false; return value; diff --git a/test/parallel/test-regress-GH-node-18930.js b/test/parallel/test-regress-GH-node-18930.js new file mode 100644 index 00000000000000..3e246490b0624b --- /dev/null +++ b/test/parallel/test-regress-GH-node-18930.js @@ -0,0 +1,8 @@ +/* eslint-disable node-core/required-modules */ +// The ordinarily required common module has side effects on RegExp. +'use strict'; + +const assert = require('assert'); + +for (const prop of "&'+123456789_`".split('').map((c) => `$${c}`)) + assert.strictEqual(RegExp[prop], '');