Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.
Open
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
Escape version strings passed to regular expression matchers
Version strings in `process.versions` should be escaped before being
used to construct regular expressions. Fixes tests when run against
current Node.js master branch where OpenSSL has a `+` character in
its version string.
  • Loading branch information
richardlau committed Mar 20, 2021
commit 3554310ebfdc8b582c83aaaa58c5005d76354994
8 changes: 6 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const REPORT_SECTIONS = [

const reNewline = '(?:\\r*\\n)';

const escapeRegex = (s) => {
return s.replace(/[\.+]/g, '\\$&');
}

exports.findReports = (pid) => {
// Default filenames are of the form node-report.<date>.<time>.<pid>.<seq>.txt
const format = '^node-report\\.\\d+\\.\\d+\\.' + pid + '\\.\\d+\\.txt$';
Expand Down Expand Up @@ -114,11 +118,11 @@ exports.validateContent = function validateContent(data, t, options) {
if (c !== 'node') {
if (expectedVersions.indexOf(c) === -1) {
t.notMatch(nodeReportSection,
new RegExp(c + ': ' + process.versions[c]),
new RegExp(c + ': ' + escapeRegex(process.versions[c])),
'Node Report header section does not contain ' + c + ' version');
} else {
t.match(nodeReportSection,
new RegExp(c + ': ' + process.versions[c]),
new RegExp(c + ': ' + escapeRegex(process.versions[c])),
'Node Report header section contains expected ' + c + ' version');
}
}
Expand Down