Fix for regex issue with product autocomplete

This commit is contained in:
Hillel Coren 2016-05-09 20:57:23 +03:00
parent 7317bfc8c9
commit 12c185ca49
2 changed files with 9 additions and 2 deletions

View File

@ -30991,7 +30991,7 @@ function searchData(data, key, fuzzy) {
matches = fuse.search(q);
} else {
matches = [];
substrRegex = new RegExp(q, 'i');
substrRegex = new RegExp(escapeRegExp(q), 'i');
$.each(data, function(i, obj) {
if (substrRegex.test(obj[key])) {
matches.push(obj);
@ -31002,6 +31002,9 @@ function searchData(data, key, fuzzy) {
}
};
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
var NINJA = NINJA || {};
NINJA.TEMPLATES = {

View File

@ -1097,7 +1097,7 @@ function searchData(data, key, fuzzy) {
matches = fuse.search(q);
} else {
matches = [];
substrRegex = new RegExp(q, 'i');
substrRegex = new RegExp(escapeRegExp(q), 'i');
$.each(data, function(i, obj) {
if (substrRegex.test(obj[key])) {
matches.push(obj);
@ -1107,3 +1107,7 @@ function searchData(data, key, fuzzy) {
cb(matches);
}
};
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}