mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Escape regex special characters in tag finder
refs #2149 - Properly highlight tags with special characters ($,[,],^,etc.)
This commit is contained in:
parent
ae3c36797a
commit
9ba80ba359
1 changed files with 6 additions and 2 deletions
|
@ -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>";
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue