diff --git a/src/plugins/field_formats/common/converters/color.test.ts b/src/plugins/field_formats/common/converters/color.test.ts index 994c6d802ae3b2..617945b3d1cdcf 100644 --- a/src/plugins/field_formats/common/converters/color.test.ts +++ b/src/plugins/field_formats/common/converters/color.test.ts @@ -112,5 +112,24 @@ describe('Color Format', () => { expect(converter('<', HTML_CONTEXT_TYPE)).toBe('<'); }); + + test('returns original value (escaped) on regex with syntax error', () => { + const colorer = new ColorFormat( + { + fieldType: 'string', + colors: [ + { + regex: 'nogroup(', + text: 'blue', + background: 'yellow', + }, + ], + }, + jest.fn() + ); + const converter = colorer.getConverterFor(HTML_CONTEXT_TYPE) as Function; + + expect(converter('<', HTML_CONTEXT_TYPE)).toBe('<'); + }); }); }); diff --git a/src/plugins/field_formats/common/converters/color.tsx b/src/plugins/field_formats/common/converters/color.tsx index 3e5ff97830479a..197468fc1592a1 100644 --- a/src/plugins/field_formats/common/converters/color.tsx +++ b/src/plugins/field_formats/common/converters/color.tsx @@ -35,7 +35,11 @@ export class ColorFormat extends FieldFormat { switch (this.param('fieldType')) { case 'string': return findLast(this.param('colors'), (colorParam: typeof DEFAULT_CONVERTER_COLOR) => { - return new RegExp(colorParam.regex).test(val as string); + try { + return new RegExp(colorParam.regex).test(val as string); + } catch (e) { + return false; + } }); case 'number':