Changeset 23229


Ignore:
Timestamp:
Jun 15, 2013, 3:50:10 PM (7 years ago)
Author:
mistic100
Message:

escape special chars used in regex
https://github.com/MartinKoerner/jquery-tokeninput/commit/cc8eab541ad1371c6f0c6730c0154908eb105f5d

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/themes/default/js/plugins/jquery.tokeninput.js

    r11008 r23229  
    577577    // Highlight the query part of the search term
    578578    function highlight_term(value, term) {
    579         return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
     579        return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + escape_regexp_chars(term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
     580    }
     581   
     582    function escape_regexp_chars(string) {
     583        var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
     584        return string.replace(specials, "\\$&");
    580585    }
    581586
Note: See TracChangeset for help on using the changeset viewer.