@@ -268,6 +268,16 @@ function getTotalCount (total) {
268
268
return typeof total === 'number' ? total : total . value
269
269
}
270
270
271
+ function escapeRegex ( str ) {
272
+ return str
273
+ . replace ( / [ \* \+ \- = ~ > < \" \? ^ \$ { } \( \) \: \! \/ [ \] \\ \s ] / g, '\\$&' ) // replace single character special characters
274
+ . replace ( / \| \| / g, '\\||' ) // replace ||
275
+ . replace ( / \& \& / g, '\\&&' ) // replace &&
276
+ . replace ( / A N D / g, '\\A\\N\\D' ) // replace AND
277
+ . replace ( / O R / g, '\\O\\R' ) // replace OR
278
+ . replace ( / N O T / g, '\\N\\O\\T' ) ; // replace NOT
279
+ }
280
+
271
281
async function getOrganizationId ( handle ) {
272
282
const DBHelper = require ( '../models/index' ) . DBHelper
273
283
@@ -573,6 +583,7 @@ function setUserAttributesFiltersToEsQuery (filterClause, attributes) {
573
583
attribute . value = [ attribute . value ]
574
584
}
575
585
586
+
576
587
filterClause . push ( {
577
588
nested : {
578
589
path : USER_ATTRIBUTE . esDocumentPath ,
@@ -586,8 +597,8 @@ function setUserAttributesFiltersToEsQuery (filterClause, attributes) {
586
597
should : attribute . value . map ( val => {
587
598
return {
588
599
query_string : {
589
- default_field : `${ [ USER_ATTRIBUTE . esDocumentValueStringQuery ] } ` ,
590
- query : `*${ val . replace ( / + / g, ' ' ) . split ( ' ' ) . join ( '* AND *' ) } *`
600
+ default_field : `${ [ USER_ATTRIBUTE . esDocumentValueQuery ] } ` ,
601
+ query : `*${ val . replace ( / + / g, ' ' ) . split ( ' ' ) . map ( p => escapeRegex ( p ) ) . join ( '* AND *' ) } *`
591
602
}
592
603
}
593
604
} ) ,
@@ -711,7 +722,7 @@ function buildEsQueryFromFilter (filter) {
711
722
* @param {* } char the char to check
712
723
*/
713
724
function isRegexReserved ( char ) {
714
- const reserved = '[^$.|?*+(){} \\'
725
+ const reserved = '^$#@&<>~.?+*|{}[]()" \\'
715
726
return reserved . indexOf ( char ) !== - 1
716
727
}
717
728
0 commit comments