@@ -268,6 +268,16 @@ function getTotalCount (total) {
268268 return typeof total === 'number' ? total : total . value
269269}
270270
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+
271281async function getOrganizationId ( handle ) {
272282 const DBHelper = require ( '../models/index' ) . DBHelper
273283
@@ -573,6 +583,7 @@ function setUserAttributesFiltersToEsQuery (filterClause, attributes) {
573583 attribute . value = [ attribute . value ]
574584 }
575585
586+
576587 filterClause . push ( {
577588 nested : {
578589 path : USER_ATTRIBUTE . esDocumentPath ,
@@ -586,8 +597,8 @@ function setUserAttributesFiltersToEsQuery (filterClause, attributes) {
586597 should : attribute . value . map ( val => {
587598 return {
588599 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 *' ) } *`
591602 }
592603 }
593604 } ) ,
@@ -711,7 +722,7 @@ function buildEsQueryFromFilter (filter) {
711722 * @param {* } char the char to check
712723 */
713724function isRegexReserved ( char ) {
714- const reserved = '[^$.|?*+(){} \\'
725+ const reserved = '^$#@&<>~.?+*|{}[]()" \\'
715726 return reserved . indexOf ( char ) !== - 1
716727}
717728
0 commit comments