Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 4776f80

Browse files
committed
Fixes u-bahn-app #295: unescaping URI encoded querystring and no longer filters out non-alphanumeric text from search keyword
1 parent b0b3d32 commit 4776f80

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/common/es-helper.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const config = require('config')
22
const _ = require('lodash')
3+
const querystring = require('querystring')
34
const logger = require('../common/logger')
45
const groupApi = require('./group-api')
56
const appConst = require('../consts')
@@ -735,7 +736,7 @@ function buildEsQueryToGetAttributeValues (attributeId, attributeValue, size) {
735736
values: {
736737
terms: {
737738
field: USER_ATTRIBUTE.esDocumentValueQuery,
738-
include: `.*${attributeValue.replace(/[A-Za-z]/g, c => `[${c.toLowerCase()}${c.toUpperCase()}]`)}.*`,
739+
include: `.*${attributeValue.replace(/[^a-zA-Z]+/gi, c => `[${c}]`).replace(/[A-Za-z]/g, c => `[${c.toLowerCase()}${c.toUpperCase()}]`)}.*`,
739740
order: {
740741
_key: 'asc'
741742
},
@@ -1175,6 +1176,7 @@ async function searchUsers (authUser, filter, params) {
11751176

11761177
const authUserOrganizationId = filter.organizationId
11771178
const filterKey = Object.keys(userFilters)
1179+
11781180
for (const key of filterKey) {
11791181
const resolved = await resolveUserFilterFromDb(userFilters[key], authUser, authUserOrganizationId)
11801182
resolvedUserFilters.push(resolved)
@@ -1257,11 +1259,11 @@ async function searchUsers (authUser, filter, params) {
12571259
* @param {Object} param0 The attribute id and the attribute value properties
12581260
*/
12591261
async function searchAttributeValues ({ attributeId, attributeValue }) {
1260-
const esQuery = buildEsQueryToGetAttributeValues(attributeId, attributeValue, 5)
1262+
const esQuery = buildEsQueryToGetAttributeValues(attributeId, querystring.unescape(attributeValue), 5)
12611263
logger.debug(`ES query for searching attribute values: ${JSON.stringify(esQuery, null, 2)}`)
12621264

12631265
const esResult = await esClient.search(esQuery)
1264-
1266+
logger.debug(`ES Result: ${JSON.stringify(esResult, null, 2)}`)
12651267
const result = []
12661268
const attributes = esResult.aggregations.attributes.ids.buckets
12671269

0 commit comments

Comments
 (0)