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:
@@ -1,4 +1,4 @@
|
|||||||
import { stringToJsRegex } from '../../text/string';
|
import { stringStartsAsRegEx, stringToJsRegex } from '../../text/string';
|
||||||
import { DataFrame } from '../../types/dataFrame';
|
import { DataFrame } from '../../types/dataFrame';
|
||||||
import { FrameMatcherInfo } from '../../types/transformations';
|
import { FrameMatcherInfo } from '../../types/transformations';
|
||||||
|
|
||||||
@@ -12,9 +12,20 @@ const refIdMatcher: FrameMatcherInfo<string> = {
|
|||||||
defaultOptions: 'A',
|
defaultOptions: 'A',
|
||||||
|
|
||||||
get: (pattern: string) => {
|
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 (frame: DataFrame) => {
|
||||||
return regex.test(frame.refId || '');
|
return regex?.test(frame.refId || '') ?? frame.refId === pattern;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ describe('filterByRefId transformer', () => {
|
|||||||
const cfg = {
|
const cfg = {
|
||||||
id: DataTransformerID.filterByRefId,
|
id: DataTransformerID.filterByRefId,
|
||||||
options: {
|
options: {
|
||||||
include: 'A|B',
|
include: '/A|B/',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user