fix: GEN-1856 encode and escape search value for the tag search (#18285)

* fix: GEN-1856 encode and escape search value for the tag

* fix test

* add missing import

(cherry picked from commit 3b182c91c8a53d11aa6fb5f880e917556cb087a7)
This commit is contained in:
Chirag Madlani 2024-10-16 18:15:07 +05:30
parent 231cef6490
commit 2d4537c4d8
2 changed files with 10 additions and 1 deletions

View File

@ -16,6 +16,12 @@ import tagClassBase, { TagClassBase } from './TagClassBase';
jest.mock('../rest/searchAPI');
jest.mock('./StringsUtils', () => ({
getEncodedFqn: jest.fn().mockReturnValue('test'),
escapeESReservedCharacters: jest.fn().mockReturnValue('test'),
}));
describe('TagClassBase', () => {
beforeEach(() => {
(searchQuery as jest.Mock).mockClear();

View File

@ -13,11 +13,14 @@
import { PAGE_SIZE } from '../constants/constants';
import { SearchIndex } from '../enums/search.enum';
import { searchQuery } from '../rest/searchAPI';
import { escapeESReservedCharacters, getEncodedFqn } from './StringsUtils';
class TagClassBase {
public async getTags(searchText: string, page: number) {
// this is to esacpe and encode any chars which is known by ES search internally
const encodedValue = getEncodedFqn(escapeESReservedCharacters(searchText));
const res = await searchQuery({
query: `*${searchText}*`,
query: `*${encodedValue}*`,
filters: 'disabled:false',
pageNumber: page,
pageSize: PAGE_SIZE,