Fix: Prevents crash when searchFilter is non string (#20526)

This commit is contained in:
Hugo Häggmark 2019-11-21 06:21:36 +01:00 committed by GitHub
parent 2079386a7d
commit e03d702d0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -85,6 +85,14 @@ describe('containsSearchFilter', () => {
});
});
describe('when called with an object', () => {
it('then it should return false', () => {
const result = containsSearchFilter({});
expect(result).toBe(false);
});
});
describe(`when called with a query without ${SEARCH_FILTER_VARIABLE}`, () => {
it('then it should return false', () => {
const result = containsSearchFilter('$app.*');

View File

@ -18,8 +18,8 @@ export const variableRegexExec = (variableString: string) => {
export const SEARCH_FILTER_VARIABLE = '__searchFilter';
export const containsSearchFilter = (query: string): boolean =>
query ? query.indexOf(SEARCH_FILTER_VARIABLE) !== -1 : false;
export const containsSearchFilter = (query: string | unknown): boolean =>
query && typeof query === 'string' ? query.indexOf(SEARCH_FILTER_VARIABLE) !== -1 : false;
export const getSearchFilterScopedVar = (args: {
query: string;