[fieldFormats/colors] escape style values

This commit is contained in:
spalger 2016-10-20 15:08:37 -07:00
parent a69ab2df1b
commit 3a5095bd6e

View file

@ -5,6 +5,7 @@ import colorTemplate from 'ui/stringify/editors/color.html';
export default function ColorFormatProvider(Private) {
const FieldFormat = Private(IndexPatternsFieldFormatProvider);
const convertTemplate = _.template('<span style="<%- style %>"><%- val %></span>');
const DEFAULT_COLOR = {
range: `${Number.NEGATIVE_INFINITY}:${Number.POSITIVE_INFINITY}`,
text: '#000000',
@ -50,9 +51,10 @@ export default function ColorFormatProvider(Private) {
if (!color) return _.asPrettyString(val);
const styleColor = color.text ? `color: ${color.text};` : '';
const styleBackgroundColor = color.background ? `background-color: ${color.background};` : '';
return `<span style="${styleColor}${styleBackgroundColor}">${_.escape(val)}</span>`;
let style = '';
if (color.text) style += `color: ${color.text};`;
if (color.background) style += `background-color: ${color.background};`;
return convertTemplate({ val, style });
}
};