mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ValueMapping: Add support for regex replacement over multiple lines (#49607)
This commit is contained in:
parent
8b509eb6dd
commit
e402b3617b
@ -34,7 +34,7 @@ export function stringToJsRegex(str: string): RegExp {
|
||||
return new RegExp(`^${str}$`);
|
||||
}
|
||||
|
||||
const match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
|
||||
const match = str.match(new RegExp('^/(.*?)/(g?i?m?y?s?)$'));
|
||||
|
||||
if (!match) {
|
||||
throw new Error(`'${str}' is not a valid regular expression.`);
|
||||
|
@ -85,6 +85,16 @@ const testSet2: ValueMapping[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const testSet3: ValueMapping[] = [
|
||||
{
|
||||
type: MappingType.RegexToText,
|
||||
options: {
|
||||
pattern: '/.*/s',
|
||||
result: { text: 'WOW IT REPLACED EVERYTHING OVER MULTIPLE LINES' },
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe('Format value with value mappings', () => {
|
||||
it('should return null with no valuemappings', () => {
|
||||
const valueMappings: ValueMapping[] = [];
|
||||
@ -194,6 +204,12 @@ describe('Format value with regex mappings', () => {
|
||||
it('should not replace match when replace text is null', () => {
|
||||
expect(getValueMappingResult(testSet2, 'hello my name is')).toEqual({ color: 'red' });
|
||||
});
|
||||
|
||||
it('supports replacing over multiple lines', () => {
|
||||
expect(getValueMappingResult(testSet3, 'hello \n my name is')).toEqual({
|
||||
text: 'WOW IT REPLACED EVERYTHING OVER MULTIPLE LINES',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNumeric', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user