mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Matchers: Require explicit regexp syntax in byRefId matcher (#96358)
This commit is contained in:
parent
bfecce320a
commit
7038bbe318
@ -1,4 +1,4 @@
|
||||
import { stringToJsRegex } from '../../text/string';
|
||||
import { stringStartsAsRegEx, stringToJsRegex } from '../../text/string';
|
||||
import { DataFrame } from '../../types/dataFrame';
|
||||
import { FrameMatcherInfo } from '../../types/transformations';
|
||||
|
||||
@ -12,9 +12,20 @@ const refIdMatcher: FrameMatcherInfo<string> = {
|
||||
defaultOptions: 'A',
|
||||
|
||||
get: (pattern: string) => {
|
||||
const regex = stringToJsRegex(pattern);
|
||||
let regex: RegExp | null = null;
|
||||
|
||||
if (stringStartsAsRegEx(pattern)) {
|
||||
try {
|
||||
regex = stringToJsRegex(pattern);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.warn(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (frame: DataFrame) => {
|
||||
return regex.test(frame.refId || '');
|
||||
return regex?.test(frame.refId || '') ?? frame.refId === pattern;
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -42,7 +42,7 @@ describe('filterByRefId transformer', () => {
|
||||
const cfg = {
|
||||
id: DataTransformerID.filterByRefId,
|
||||
options: {
|
||||
include: 'A|B',
|
||||
include: '/A|B/',
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user