Skip to content

Commit

Permalink
Update color field formatter (elastic#15837) (elastic#15849)
Browse files Browse the repository at this point in the history
* Updating color field formatter

* Just using single quotes, back-ticks no longer necessary

* Revising the tests
  • Loading branch information
kobelb authored Jan 4, 2018
1 parent d773efb commit b67ac57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/ui/public/stringify/__tests__/_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,26 @@ describe('Color Format', function () {
expect(converter('AB', 'html')).to.eql(
'<span ng-non-bindable><span style="color: blue;background-color: yellow;">AB</span></span>'
);

expect(converter('AB <', 'html')).to.eql(
'<span ng-non-bindable><span style="color: blue;background-color: yellow;">AB &lt;</span></span>'
);

expect(converter('a', 'html')).to.eql('<span ng-non-bindable>a</span>');
});

it('returns original value (escaped) when regex is invalid', function () {
const colorer = new ColorFormat({
fieldType: 'string',
colors: [{
regex: 'A.*',
text: 'blue',
background: 'yellow'
}]
});

const converter = colorer.getConverterFor('html');
expect(converter('<', 'html')).to.eql('<span ng-non-bindable>&lt;</span>');
});
});
});
2 changes: 1 addition & 1 deletion src/ui/public/stringify/types/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function stringifyColor(Private) {
_Color.prototype._convert = {
html(val) {
const color = this.findColorRuleForVal(val);
if (!color) return _.asPrettyString(val);
if (!color) return _.escape(_.asPrettyString(val));

let style = '';
if (color.text) style += `color: ${color.text};`;
Expand Down

0 comments on commit b67ac57

Please sign in to comment.