Skip to content
Draft
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
2 changes: 1 addition & 1 deletion test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function replaceTestDuration(str) {

const root = path.resolve(__dirname, '..', '..');
const color = '(\\[\\d+m)';
const stackTraceBasePath = new RegExp(`${color}\\(${root.replaceAll(/[\\^$*+?.()|[\]{}]/g, '\\$&')}/?${color}(.*)${color}\\)`, 'g');
const stackTraceBasePath = new RegExp(`${color}\\(${RegExp.escape(root)}/?${color}(.*)${color}\\)`, 'g');

function replaceSpecDuration(str) {
return str
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-crypto-argon2.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ for (const [algorithm, overrides, expected] of good) {
for (const [algorithm, overrides, param] of bad) {
const expected = {
code: 'ERR_OUT_OF_RANGE',
message: new RegExp(`The value of "${param}" is out of range`),
message: new RegExp(`The value of "${RegExp.escape(param)}" is out of range`),
};
const parameters = { ...defaults, ...overrides };
assert.throws(() => crypto.argon2(algorithm, parameters, () => {}), expected);
Expand All @@ -122,7 +122,7 @@ for (const [algorithm, overrides, param] of bad) {
for (const key of Object.keys(defaults)) {
const expected = {
code: 'ERR_INVALID_ARG_TYPE',
message: new RegExp(`"parameters\\.${key}"`),
message: new RegExp(`"parameters\\.${RegExp.escape(key)}"`),
};
const parameters = { ...defaults };
delete parameters[key];
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-crypto-x509.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ oans248kpal88CGqsN2so/wZKxVnpiXlPHMdiNL7hRSUqlHkUi07FrP2Htg8kjI=
'OCSP - URI': ['http://ocsp.nodejs.org/'],
'CA Issuers - URI': ['http://ca.nodejs.org/ca.cert']
}),
modulusPattern: new RegExp(`^${modulusOSSL}$`, 'i'),
modulusPattern: new RegExp(`^${RegExp.escape(modulusOSSL)}$`, 'i'),
bits: 2048,
exponent: '0x10001',
valid_from: 'Sep 3 21:40:37 2022 GMT',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-module-loading-globalpaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if (process.argv[2] === 'child') {
child_process.execFileSync(testExecPath, [ __filename, 'child' ],
{ encoding: 'utf8', env: env });
},
new RegExp(`Cannot find module '${pkgName}'`));
new RegExp(`Cannot find module '${RegExp.escape(pkgName)}'`));

// Test module in $HOME/.node_modules.
const modHomeDir = path.join(testFixturesDir, 'home-pkg-in-node_modules');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-permission-warning-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ for (const flag of warnFlags) {
]
);

assert.match(stderr.toString(), new RegExp(`SecurityWarning: The flag ${flag} must be used with extreme caution`));
assert.match(stderr.toString(), new RegExp(`SecurityWarning: The flag ${RegExp.escape(flag)} must be used with extreme caution`));
assert.strictEqual(status, 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const cliMd = path.join(rootDir, 'doc', 'api', 'cli.md');
const cliText = fs.readFileSync(cliMd, { encoding: 'utf8' });

const parseSection = (text, startMarker, endMarker) => {
const regExp = new RegExp(`${startMarker}\r?\n([^]*)\r?\n${endMarker}`);
const regExp = new RegExp(`${RegExp.escape(startMarker)}\r?\n([^]*)\r?\n${RegExp.escape(endMarker)}`);
const match = text.match(regExp);
assert(match,
`Unable to locate text between '${startMarker}' and '${endMarker}'.`);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-quic-internal-endpoint-options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ for (const { key, valid, invalid } of cases) {
const options = {};
options[key] = value;
throws(() => new QuicEndpoint(options), {
message: new RegExp(`${key}`),
message: new RegExp(`${RegExp.escape(key)}`),
}, value);
}
}
Expand Down
18 changes: 9 additions & 9 deletions test/parallel/test-release-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fs = require('fs');
const path = require('path');

const getDefine = (text, name) => {
const regexp = new RegExp(`#define\\s+${name}\\s+(.*)`);
const regexp = new RegExp(`#define\\s+${RegExp.escape(name)}\\s+(.*)`);
const match = regexp.exec(text);
assert.notStrictEqual(match, null);
return match[1];
Expand All @@ -27,7 +27,7 @@ if (!release) {
const major = getDefine(versionText, 'NODE_MAJOR_VERSION');
const minor = getDefine(versionText, 'NODE_MINOR_VERSION');
const patch = getDefine(versionText, 'NODE_PATCH_VERSION');
const versionForRegex = `${major}\\.${minor}\\.${patch}`;
const versionForRegex = RegExp.escape(`${major}.${minor}.${patch}`);

const lts = getDefine(versionText, 'NODE_VERSION_IS_LTS') !== '0';
const codename = getDefine(versionText, 'NODE_VERSION_LTS_CODENAME').slice(1, -1);
Expand All @@ -45,7 +45,7 @@ const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`;
// Check table header
let tableHeader;
if (lts) {
tableHeader = new RegExp(`<th>LTS '${codename}'</th>`);
tableHeader = new RegExp(`<th>LTS '${RegExp.escape(codename)}'</th>`);
} else {
tableHeader = /<th>Current<\/th>/;
}
Expand All @@ -57,7 +57,7 @@ const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`;
// Check title for changelog entry.
let title;
if (lts) {
title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} '${codename}' \\(LTS\\), @\\S+`);
title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} '${RegExp.escape(codename)}' \\(LTS\\), @\\S+`);
} else {
title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} \\(Current\\), @\\S+`);
}
Expand All @@ -70,20 +70,20 @@ const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`;
// Check for the link to the appropriate CHANGELOG_V*.md file.
let linkToChangelog;
if (lts) {
linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Long Term Support\\*\\*`);
linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${RegExp.escape(changelogPath)}\\) \\*\\*Long Term Support\\*\\*`);
} else {
linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Current\\*\\*`);
linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${RegExp.escape(changelogPath)}\\) \\*\\*Current\\*\\*`);
}
assert.match(mainChangelog, linkToChangelog);
// Check table header.
let tableHeader;
if (lts) {
tableHeader = new RegExp(`<th title="LTS Until \\d{4}-\\d{2}"><a href="${changelogPath}">${major}</a> \\(LTS\\)</th>`);
tableHeader = new RegExp(`<th title="LTS Until \\d{4}-\\d{2}"><a href="${RegExp.escape(changelogPath)}">${major}</a> \\(LTS\\)</th>`);
} else {
tableHeader = new RegExp(`<th title="Current"><a href="${changelogPath}">${major}</a> \\(Current\\)</th>`);
tableHeader = new RegExp(`<th title="Current"><a href="${RegExp.escape(changelogPath)}">${major}</a> \\(Current\\)</th>`);
}
assert.match(mainChangelog, tableHeader);
// Check the table contains a link to the release in the appropriate CHANGELOG_V*.md file.
const linkToVersion = new RegExp(`<b><a href="${changelogPath}#${versionForRegex}">${versionForRegex}</a></b><br/>`);
const linkToVersion = new RegExp(`<b><a href="${RegExp.escape(changelogPath)}#${versionForRegex}">${versionForRegex}</a></b><br/>`);
assert.match(mainChangelog, linkToVersion);
}
4 changes: 2 additions & 2 deletions test/parallel/test-repl-custom-eval-previews.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('with previews', () => {
);
const lines = getSingleCommandLines(output);
assert.match(lines.command, /^'Hello custom' \+ ' eval World!'/);
assert.match(lines.prompt, new RegExp(`${testingReplPrompt}$`));
assert.match(lines.prompt, new RegExp(`${RegExp.escape(testingReplPrompt)}$`));
assert.strictEqual(lines.result, "'Hello custom eval World!'");
assert.strictEqual(lines.preview, undefined);
});
Expand All @@ -62,7 +62,7 @@ describe('with previews', () => {
);
const lines = getSingleCommandLines(output);
assert.match(lines.command, /^'Hello custom' \+ ' eval World!'/);
assert.match(lines.prompt, new RegExp(`${testingReplPrompt}$`));
assert.match(lines.prompt, new RegExp(`${RegExp.escape(testingReplPrompt)}$`));
assert.strictEqual(lines.result, "'Hello custom eval World!'");
assert.match(lines.preview, /'Hello custom eval World!'/);
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2916,7 +2916,7 @@ assert.strictEqual(
util.inspect(err, { colors: true }).split('\n').forEach(common.mustCallAtLeast((line, i) => {
let expected = stack[i].replace(/node_modules\/(@[^/]+\/[^/]+|[^/]+)/gi, (_, m) => {
return `node_modules/\u001b[4m${m}\u001b[24m`;
}).replaceAll(new RegExp(`(\\(?${escapedCWD}(\\\\|/))`, 'gi'), (_, m) => {
}).replaceAll(new RegExp(`(\\(?${RegExp.escape(escapedCWD)}(\\\\|/))`, 'gi'), (_, m) => {
return `\x1B[90m${m}\x1B[39m`;
});
if (expected.includes(process.cwd()) && expected.endsWith(')')) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-watch-mode-kill-signal-default.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ child.on('message', (msg) => {

await once(child, 'exit');

assert.match(stdout, new RegExp(`__SIGTERM received__ ${firstGrandchildPid}`));
assert.doesNotMatch(stdout, new RegExp(`__SIGINT received__ ${firstGrandchildPid}`));
assert.match(stdout, new RegExp(`__SIGTERM received__ ${RegExp.escape(firstGrandchildPid)}`));
assert.doesNotMatch(stdout, new RegExp(`__SIGINT received__ ${RegExp.escape(firstGrandchildPid)}`));
4 changes: 2 additions & 2 deletions test/parallel/test-watch-mode-kill-signal-override.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ await once(child, 'exit');
// The second grandchild, if there is one, could receive SIGTERM if it's killed as a
// consequence of the parent being killed in this process instead of being killed by the
// parent for file changes. Here we only care about the first grandchild.
assert.match(stdout, new RegExp(`__SIGINT received__ ${firstGrandchildPid}`));
assert.doesNotMatch(stdout, new RegExp(`__SIGTERM received__ ${firstGrandchildPid}`));
assert.match(stdout, new RegExp(`__SIGINT received__ ${RegExp.escape(firstGrandchildPid)}`));
assert.doesNotMatch(stdout, new RegExp(`__SIGTERM received__ ${RegExp.escape(firstGrandchildPid)}`));
4 changes: 2 additions & 2 deletions test/parallel/test-whatwg-webstreams-encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString();
() => Reflect.get(TextDecoderStream.prototype, getter, {}), {
name: 'TypeError',
message: /Cannot read private member/,
stack: new RegExp(`at get ${getter}`)
stack: new RegExp(`at get ${RegExp.escape(getter)}`)
}
);
});
Expand Down Expand Up @@ -79,7 +79,7 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString();
() => Reflect.get(TextDecoderStream.prototype, getter, {}), {
name: 'TypeError',
message: /Cannot read private member/,
stack: new RegExp(`at get ${getter}`)
stack: new RegExp(`at get ${RegExp.escape(getter)}`)
}
);
});
Expand Down
Loading