Skip to content

Commit

Permalink
escape special chars used in regex
Browse files Browse the repository at this point in the history
MartinKoerner/jquery-tokeninput@cc8eab5

git-svn-id: http://piwigo.org/svn/trunk@23229 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jun 15, 2013
1 parent c3574ce commit 212d37a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion themes/default/js/plugins/jquery.tokeninput.js
Expand Up @@ -576,7 +576,12 @@ $.TokenList = function (input, url_or_data, settings) {

// Highlight the query part of the search term
function highlight_term(value, term) {
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + escape_regexp_chars(term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
}

function escape_regexp_chars(string) {
var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
return string.replace(specials, "\\$&");
}

// Populate the results dropdown with some results
Expand Down

0 comments on commit 212d37a

Please sign in to comment.