Skip to content

bootstrap_node: remove side effects on RegExp #19138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/internal/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe a more descriptive name than "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;
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-regress-GH-node-18930.js
Original file line number Diff line number Diff line change
@@ -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], '');