diff --git a/ghost/admin/views/editor-tag-widget.js b/ghost/admin/views/editor-tag-widget.js index 3c157467b2..a3a89ed829 100644 --- a/ghost/admin/views/editor-tag-widget.js +++ b/ghost/admin/views/editor-tag-widget.js @@ -106,8 +106,11 @@ styles = { left: $target.position().left }, - maxSuggestions = 5, // Limit the suggestions number - regexTerm = searchTerm.replace(/(\s+)/g, "(<[^>]+>)*$1(<[^>]+>)*"), + // Limit the suggestions number + maxSuggestions = 5, + // Escape regex special characters + escapedTerm = searchTerm.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&'), + regexTerm = escapedTerm.replace(/(\s+)/g, "(<[^>]+>)*$1(<[^>]+>)*"), regexPattern = new RegExp("(" + regexTerm + ")", "i"); this.$suggestions.css(styles); @@ -120,6 +123,7 @@ _.each(matchingTags, function (matchingTag) { var highlightedName, suggestionHTML; + highlightedName = matchingTag.name.replace(regexPattern, function (match, p1) { return "" + _.escape(p1) + ""; });