Skip to content

Commit 41af375

Browse files
fix: escaping regex in linting script (#116)
1 parent a394595 commit 41af375

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

.github/scripts/lint-readme.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const directoryPath = process.argv[2] || './gh-cli';
1212
const headingLevel = process.argv[3] || '###';
1313
const parentHeading = process.argv[4] || '## Scripts';
1414

15+
// Escape RegExp special characters
16+
function escapeRegExp(string) {
17+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
18+
}
1519
const readmePath = path.join(directoryPath, 'README.md');
1620

1721
// Read README.md content
@@ -96,7 +100,7 @@ allScripts.forEach(file => {
96100
const scriptsSection = readme.split(`${parentHeading}\n`)[1];
97101

98102
// Extract all ### headings from the scripts section
99-
const regex = new RegExp(`${headingLevel} .*`, 'g');
103+
const regex = new RegExp(`${escapeRegExp(headingLevel)} .*`, 'g');
100104
const headings = scriptsSection.match(regex);
101105

102106
// Check that all scripts mentioned in the README.md actually exist in the repository

0 commit comments

Comments
 (0)