Skip to content

Commit

Permalink
fix: encode global search keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Nov 22, 2023
1 parent 272968c commit f78188e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
23 changes: 11 additions & 12 deletions src/controllers/global-search.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,17 @@ export class GlobalSearchController {
globalSearchMapping.categories,
(category: any) => category.url.length > 0,
).map((category: any) => {
return axios.get(
category.url
.replace(
'<filterStr>',
buildGlobalSearchFilterString(
category.filterFields,
category.filterTemplate,
keywords,
),
)
.replace('<keyword>', keyword),
);
const call = category.url
.replace(
'<filterStr>',
buildGlobalSearchFilterString(
category.filterFields,
category.filterTemplate,
keywords,
),
)
.replace('<keyword>', keyword);
return axios.get(call);
});
return axios
.all(calls)
Expand Down
7 changes: 6 additions & 1 deletion src/utils/filtering/globalsearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export function buildGlobalSearchFilterString(

keywords.forEach((keyword: string) => {
const fieldStrArray: string[] = fields.map((field: string) =>
template.replace('<field>', field).replace('<value>', `'${keyword}'`),
template
.replace('<field>', field)
.replace(
'<value>',
`'${encodeURIComponent(keyword.replace(/'/g, "''"))}'`,
),
);
strArray.push(`(${fieldStrArray.join(` ${filteringUtils.or_operator} `)})`);
});
Expand Down

0 comments on commit f78188e

Please sign in to comment.