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

pull/20486/head
Hugo Häggmark 6 years ago committed by GitHub
parent 2079386a7d
commit e03d702d0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      public/app/features/templating/specs/variable.test.ts
  2. 4
      public/app/features/templating/variable.ts

@ -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.*');

@ -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;

Loading…
Cancel
Save