From f1345fd265bcd0ef751baa2dd44e234c9789a4ca Mon Sep 17 00:00:00 2001 From: Ilias Deros Date: Wed, 21 Oct 2015 11:43:20 -0400 Subject: [PATCH] escape special characters when matching highlight string --- script/autocomplete.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/script/autocomplete.js b/script/autocomplete.js index 377ad0f..cd6d2dd 100644 --- a/script/autocomplete.js +++ b/script/autocomplete.js @@ -267,6 +267,7 @@ app.filter('highlight', ['$sce', function ($sce) { return function (input, searchParam) { if (typeof input === 'function') return ''; if (searchParam) { + searchParam = escapeSpecialCharacters(searchParam); var words = '(' + searchParam.split(/\ /).join(' |') + '|' + searchParam.split(/\ /).join('|') + @@ -296,3 +297,8 @@ app.directive('suggestion', function(){ } }; }); + +// escape characters that may be interpreted as regex expressions +function escapeSpecialCharacters(string) { + return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); +} \ No newline at end of file