Merge pull request #2496 from halfdan/more-tag-fuddling

Escape regex special characters in tag finder
This commit is contained in:
Hannah Wolfe 2014-03-24 20:20:51 +00:00
commit e9fb7ae044

View File

@ -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 "<mark>" + _.escape(p1) + "</mark>";
});