]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12125 Escape special characters before constructing regex
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 21 May 2019 06:34:52 +0000 (08:34 +0200)
committerSonarTech <sonartech@sonarsource.com>
Mon, 27 May 2019 18:21:09 +0000 (20:21 +0200)
server/sonar-docs/src/templates/page.tsx

index b468d39971c5032900fda7d04d3c21ecf046afdc..e0239d2bf2767c42a78836d3f1ca990b716a6d07 100644 (file)
@@ -157,7 +157,10 @@ function removeExtraHeadings(content: string, headings: MarkdownHeading[]) {
     .filter(heading => !heading.value || !heading.value.match(/Table of content/i))
     .filter(heading => {
       const regex = new RegExp(
-        `<!-- sonarcloud -->[\\s\\S]*<h2>${heading.value}<\\/h2>[\\s\\S]*<!-- /sonarcloud -->`,
+        `<!-- sonarcloud -->[\\s\\S]*<h2>${heading.value!.replace(
+          /[.*+?^${}()|[\]\\]/g,
+          '\\$&'
+        )}<\\/h2>[\\s\\S]*<!-- /sonarcloud -->`,
         'gim'
       );
       return !content.match(regex);