Просмотр исходного кода

Fix: Crowi.appendEditSectionButtons

* search text with escape-string-regexp
Yuki Takei 8 лет назад
Родитель
Сommit
7a6f3156d7
1 измененных файлов с 2 добавлено и 1 удалено
  1. 2 1
      resource/js/legacy/crowi.js

+ 2 - 1
resource/js/legacy/crowi.js

@@ -40,10 +40,11 @@ Crowi.appendEditSectionButtons = function(contentId, markdown) {
   $('h1,h2,h3,h4,h5,h6', $content).each(function(idx, elm) {
   $('h1,h2,h3,h4,h5,h6', $content).each(function(idx, elm) {
     // get header text string
     // get header text string
     const text = $(this).text();
     const text = $(this).text();
+    const escapedText = escapeStringRegexp(text);
 
 
     // search pos for '# ...'
     // search pos for '# ...'
     // https://regex101.com/r/y5rpO5/1
     // https://regex101.com/r/y5rpO5/1
-    const regexp = new RegExp(`[^\r\n]*#+[^\r\n]*${text}[^\r\n]*`);
+    const regexp = new RegExp(`[^\r\n]*#+[^\r\n]*${escapedText}[^\r\n]*`);
     let position = markdown.search(regexp);
     let position = markdown.search(regexp);
     if (position < 0) { // if not found, search with header text only
     if (position < 0) { // if not found, search with header text only
       position = markdown.search(text);
       position = markdown.search(text);