@@ -706,6 +706,15 @@ function buildEsQueryFromFilter (filter) {
706
706
return setFilterValueToEsQuery ( esQuery , matchField , filter . value , filter . queryField )
707
707
}
708
708
709
+ /**
710
+ * Returns if char is one of the reserved regex characters
711
+ * @param {* } char the char to check
712
+ */
713
+ function isRegexReserved ( char ) {
714
+ const reserved = '[^$.|?*+(){}\\'
715
+ return reserved . indexOf ( char ) !== - 1
716
+ }
717
+
709
718
/**
710
719
* Build ES Query to get attribute values by attributeId
711
720
* @param attributeId the attribute whose values to fetch
@@ -736,7 +745,7 @@ function buildEsQueryToGetAttributeValues (attributeId, attributeValue, size) {
736
745
values : {
737
746
terms : {
738
747
field : USER_ATTRIBUTE . esDocumentValueQuery ,
739
- include : `.*${ attributeValue . replace ( / [ ^ a - z A - Z ] + / gi , c => `[${ c } ]` ) . replace ( / [ A - Z a - z ] / g, c => `[${ c . toLowerCase ( ) } ${ c . toUpperCase ( ) } ]` ) } .*` ,
748
+ include : `.*${ attributeValue . replace ( / [ ^ a - z A - Z ] / g , c => `[${ ! isRegexReserved ( c ) ? c : '\\' + c } ]` ) . replace ( / [ A - Z a - z ] / g, c => `[${ c . toLowerCase ( ) } ${ c . toUpperCase ( ) } ]` ) } .*` ,
740
749
order : {
741
750
_key : 'asc'
742
751
} ,
@@ -1263,6 +1272,7 @@ async function searchAttributeValues ({ attributeId, attributeValue }) {
1263
1272
logger . debug ( `ES query for searching attribute values: ${ JSON . stringify ( esQuery , null , 2 ) } ` )
1264
1273
1265
1274
const esResult = await esClient . search ( esQuery )
1275
+ logger . debug ( `ES Result: ${ JSON . stringify ( esResult , null , 2 ) } ` )
1266
1276
const result = [ ]
1267
1277
const attributes = esResult . aggregations . attributes . ids . buckets
1268
1278
0 commit comments