Skip to content

Commit

Permalink
fix ff color editor crash (#127292) (#127606)
Browse files Browse the repository at this point in the history
(cherry picked from commit b4b08a5)

Co-authored-by: Anton Dosov <[email protected]>
  • Loading branch information
kibanamachine and Dosant authored Mar 14, 2022
1 parent d2d7763 commit 5151a3e
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 5151a3e

Please sign in to comment.