Skip to content

Commit

Permalink
Merge pull request TryGhost#2496 from halfdan/more-tag-fuddling
Browse files Browse the repository at this point in the history
Escape regex special characters in tag finder
  • Loading branch information
ErisDS committed Mar 24, 2014
2 parents 1fbe4d0 + 9ba80ba commit 3ee6987
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/client/views/editor-tag-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -120,6 +123,7 @@
_.each(matchingTags, function (matchingTag) {
var highlightedName,
suggestionHTML;

highlightedName = matchingTag.name.replace(regexPattern, function (match, p1) {
return "<mark>" + _.escape(p1) + "</mark>";
});
Expand Down

0 comments on commit 3ee6987

Please sign in to comment.