From bd89ee4f80a5886c67a3f3330bdb270a8f28cdd8 Mon Sep 17 00:00:00 2001 From: Josh Johanning Date: Sat, 23 Aug 2025 07:45:32 -0500 Subject: [PATCH] fix: escaping regex in linting script --- .github/scripts/lint-readme.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/scripts/lint-readme.js b/.github/scripts/lint-readme.js index fd72f12..9b044a3 100644 --- a/.github/scripts/lint-readme.js +++ b/.github/scripts/lint-readme.js @@ -12,6 +12,10 @@ const directoryPath = process.argv[2] || './gh-cli'; const headingLevel = process.argv[3] || '###'; const parentHeading = process.argv[4] || '## Scripts'; +// Escape RegExp special characters +function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +} const readmePath = path.join(directoryPath, 'README.md'); // Read README.md content @@ -96,7 +100,7 @@ allScripts.forEach(file => { const scriptsSection = readme.split(`${parentHeading}\n`)[1]; // Extract all ### headings from the scripts section -const regex = new RegExp(`${headingLevel} .*`, 'g'); +const regex = new RegExp(`${escapeRegExp(headingLevel)} .*`, 'g'); const headings = scriptsSection.match(regex); // Check that all scripts mentioned in the README.md actually exist in the repository