Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Escape version strings passed to regular expression matchers #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
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