@@ -8,7 +8,7 @@ const fs = require('fs');
88const path = require ( 'path' ) ;
99
1010const getDefine = ( text , name ) => {
11- const regexp = new RegExp ( `#define\\s+${ name } \\s+(.*)` ) ;
11+ const regexp = new RegExp ( `#define\\s+${ RegExp . escape ( name ) } \\s+(.*)` ) ;
1212 const match = regexp . exec ( text ) ;
1313 assert . notStrictEqual ( match , null ) ;
1414 return match [ 1 ] ;
@@ -27,7 +27,7 @@ if (!release) {
2727const major = getDefine ( versionText , 'NODE_MAJOR_VERSION' ) ;
2828const minor = getDefine ( versionText , 'NODE_MINOR_VERSION' ) ;
2929const patch = getDefine ( versionText , 'NODE_PATCH_VERSION' ) ;
30- const versionForRegex = `${ major } \\ .${ minor } \\ .${ patch } ` ;
30+ const versionForRegex = RegExp . escape ( `${ major } .${ minor } .${ patch } ` ) ;
3131
3232const lts = getDefine ( versionText , 'NODE_VERSION_IS_LTS' ) !== '0' ;
3333const codename = getDefine ( versionText , 'NODE_VERSION_LTS_CODENAME' ) . slice ( 1 , - 1 ) ;
@@ -45,7 +45,7 @@ const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`;
4545 // Check table header
4646 let tableHeader ;
4747 if ( lts ) {
48- tableHeader = new RegExp ( `<th>LTS '${ codename } '</th>` ) ;
48+ tableHeader = new RegExp ( `<th>LTS '${ RegExp . escape ( codename ) } '</th>` ) ;
4949 } else {
5050 tableHeader = / < t h > C u r r e n t < \/ t h > / ;
5151 }
@@ -57,7 +57,7 @@ const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`;
5757 // Check title for changelog entry.
5858 let title ;
5959 if ( lts ) {
60- title = new RegExp ( `## \\d{4}-\\d{2}-\\d{2}, Version ${ versionForRegex } '${ codename } ' \\(LTS\\), @\\S+` ) ;
60+ title = new RegExp ( `## \\d{4}-\\d{2}-\\d{2}, Version ${ versionForRegex } '${ RegExp . escape ( codename ) } ' \\(LTS\\), @\\S+` ) ;
6161 } else {
6262 title = new RegExp ( `## \\d{4}-\\d{2}-\\d{2}, Version ${ versionForRegex } \\(Current\\), @\\S+` ) ;
6363 }
@@ -70,20 +70,20 @@ const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`;
7070 // Check for the link to the appropriate CHANGELOG_V*.md file.
7171 let linkToChangelog ;
7272 if ( lts ) {
73- linkToChangelog = new RegExp ( `\\[Node\\.js ${ major } \\]\\(${ changelogPath } \\) \\*\\*Long Term Support\\*\\*` ) ;
73+ linkToChangelog = new RegExp ( `\\[Node\\.js ${ major } \\]\\(${ RegExp . escape ( changelogPath ) } \\) \\*\\*Long Term Support\\*\\*` ) ;
7474 } else {
75- linkToChangelog = new RegExp ( `\\[Node\\.js ${ major } \\]\\(${ changelogPath } \\) \\*\\*Current\\*\\*` ) ;
75+ linkToChangelog = new RegExp ( `\\[Node\\.js ${ major } \\]\\(${ RegExp . escape ( changelogPath ) } \\) \\*\\*Current\\*\\*` ) ;
7676 }
7777 assert . match ( mainChangelog , linkToChangelog ) ;
7878 // Check table header.
7979 let tableHeader ;
8080 if ( lts ) {
81- tableHeader = new RegExp ( `<th title="LTS Until \\d{4}-\\d{2}"><a href="${ changelogPath } ">${ major } </a> \\(LTS\\)</th>` ) ;
81+ tableHeader = new RegExp ( `<th title="LTS Until \\d{4}-\\d{2}"><a href="${ RegExp . escape ( changelogPath ) } ">${ major } </a> \\(LTS\\)</th>` ) ;
8282 } else {
83- tableHeader = new RegExp ( `<th title="Current"><a href="${ changelogPath } ">${ major } </a> \\(Current\\)</th>` ) ;
83+ tableHeader = new RegExp ( `<th title="Current"><a href="${ RegExp . escape ( changelogPath ) } ">${ major } </a> \\(Current\\)</th>` ) ;
8484 }
8585 assert . match ( mainChangelog , tableHeader ) ;
8686 // Check the table contains a link to the release in the appropriate CHANGELOG_V*.md file.
87- const linkToVersion = new RegExp ( `<b><a href="${ changelogPath } #${ versionForRegex } ">${ versionForRegex } </a></b><br/>` ) ;
87+ const linkToVersion = new RegExp ( `<b><a href="${ RegExp . escape ( changelogPath ) } #${ versionForRegex } ">${ versionForRegex } </a></b><br/>` ) ;
8888 assert . match ( mainChangelog , linkToVersion ) ;
8989}
0 commit comments