From 22232e19ca74f38a10f677f1011de8298e32d948 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 26 Aug 2015 22:07:18 -0500
Subject: [PATCH] typeahead: Fix search on things with regex tokens, like `+`

Also, if searching for multiple words, highlight each word found
---
 scp/js/bootstrap-typeahead.js | 5 ++---
 scp/js/scp.js                 | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/scp/js/bootstrap-typeahead.js b/scp/js/bootstrap-typeahead.js
index d53630e4b..fffa189ec 100644
--- a/scp/js/bootstrap-typeahead.js
+++ b/scp/js/bootstrap-typeahead.js
@@ -158,9 +158,8 @@
   , highlighter: function (item) {
       if (!this.query)
           return item;
-      return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) {
-        return '<strong>' + match + '</strong>'
-      })
+      var exp = this.query.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&").replace(' ', '|')
+      return item.replace(new RegExp(exp, 'ig'), '<strong>$&</strong>')
     }
 
   , render: function (items) {
diff --git a/scp/js/scp.js b/scp/js/scp.js
index 0b0425e1f..e96cda1b2 100644
--- a/scp/js/scp.js
+++ b/scp/js/scp.js
@@ -256,7 +256,7 @@ var scp_prep = function() {
         source: function (typeahead, query) {
             if (last_req) last_req.abort();
             var $el = this.$element;
-            var url = $el.data('url')+'?q='+query;
+            var url = $el.data('url')+'?q='+encodeURIComponent(query);
             last_req = $.ajax({
                 url: url,
                 dataType: 'json',
-- 
GitLab