0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

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 3ee6987aa9

View file

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