mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Unescape regex string (#45137)
This commit is contained in:
parent
fd5e968bc1
commit
ec48b81388
@ -1,4 +1,4 @@
|
||||
import { PanelPluginMeta, PluginState } from '@grafana/data';
|
||||
import { PanelPluginMeta, PluginState, unEscapeStringFromRegex } from '@grafana/data';
|
||||
import { config } from 'app/core/config';
|
||||
|
||||
export function getAllPanelPluginMeta(): PanelPluginMeta[] {
|
||||
@ -12,7 +12,7 @@ export function getAllPanelPluginMeta(): PanelPluginMeta[] {
|
||||
|
||||
export function filterPluginList(
|
||||
pluginsList: PanelPluginMeta[],
|
||||
searchQuery: string,
|
||||
searchQuery: string, // Note: this will be an escaped regex string as it comes from `FilterInput`
|
||||
current: PanelPluginMeta
|
||||
): PanelPluginMeta[] {
|
||||
if (!searchQuery.length) {
|
||||
@ -24,7 +24,7 @@ export function filterPluginList(
|
||||
});
|
||||
}
|
||||
|
||||
const query = searchQuery.toLowerCase();
|
||||
const query = unEscapeStringFromRegex(searchQuery).toLowerCase();
|
||||
const first: PanelPluginMeta[] = [];
|
||||
const match: PanelPluginMeta[] = [];
|
||||
const isGraphQuery = 'graph'.startsWith(query);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { PanelPluginMeta } from '@grafana/data';
|
||||
import { PanelPluginMeta, escapeStringForRegex } from '@grafana/data';
|
||||
import { filterPluginList } from './util';
|
||||
|
||||
describe('panel state utils', () => {
|
||||
@ -8,7 +8,18 @@ describe('panel state utils', () => {
|
||||
{ id: 'timeseries', name: 'Graph (old)' },
|
||||
{ id: 'timeline', name: 'Timeline' },
|
||||
];
|
||||
const found = filterPluginList(pluginsList, 'gra', { id: 'xyz' } as any);
|
||||
const found = filterPluginList(pluginsList, escapeStringForRegex('gra'), { id: 'xyz' } as any);
|
||||
expect(found.map((v) => v.id)).toEqual(['graph', 'timeseries']);
|
||||
});
|
||||
|
||||
it('should handle escaped regex characters in the search query (e.g. -)', async () => {
|
||||
const pluginsList: PanelPluginMeta[] = [
|
||||
{ id: 'graph', name: 'Graph (old)' } as any,
|
||||
{ id: 'timeseries', name: 'Graph (old)' },
|
||||
{ id: 'timeline', name: 'Timeline' },
|
||||
{ id: 'panelwithdashes', name: 'Panel-With-Dashes' },
|
||||
];
|
||||
const found = filterPluginList(pluginsList, escapeStringForRegex('panel-'), { id: 'xyz' } as any);
|
||||
expect(found.map((v) => v.id)).toEqual(['panelwithdashes']);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user