Skip to content

Commit

Permalink
fix ff color editor crash (elastic#127292)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant authored and maksimkovalev committed Mar 18, 2022
1 parent 426620d commit dff31ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/plugins/field_formats/common/converters/color.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,24 @@ describe('Color Format', () => {

expect(converter('<', HTML_CONTEXT_TYPE)).toBe('&lt;');
});

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('&lt;');
});
});
});
6 changes: 5 additions & 1 deletion src/plugins/field_formats/common/converters/color.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit dff31ed

Please sign in to comment.