From c1089eaae45e5dcf5c364b7444ce51d6596a218b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Oct 2015 10:21:26 -0700 Subject: [PATCH] Reference issue #385 have prevented attempted pattern matching on empty strings --- src/jquery.autocomplete.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index 94b5934f..a3386c39 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -127,15 +127,19 @@ $.Autocomplete = Autocomplete; Autocomplete.formatResult = function (suggestion, currentValue) { - var pattern = '(' + utils.escapeRegExChars(currentValue) + ')'; - - return suggestion.value - .replace(new RegExp(pattern, 'gi'), '$1<\/strong>') - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/<(\/?strong)>/g, '<$1>'); + if (currentValue) { + var pattern = '(' + utils.escapeRegExChars(currentValue) + ')'; + + return suggestion.value + .replace(new RegExp(pattern, 'gi'), '$1<\/strong>') + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/<(\/?strong)>/g, '<$1>'); + } else { + return suggestion.value; + } }; Autocomplete.prototype = {