From 5775c0a341d301644b9d7c97ef52d0a82201d592 Mon Sep 17 00:00:00 2001 From: bergquist Date: Sun, 7 Feb 2016 17:08:48 +0100 Subject: [PATCH] feat(table): remove option to disable html encoding --- public/app/plugins/panel/table/renderer.ts | 37 +++++++------------ .../panel/table/specs/renderer_specs.ts | 9 +---- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/public/app/plugins/panel/table/renderer.ts b/public/app/plugins/panel/table/renderer.ts index 42b9aeeb2d2..c39f1d42bcf 100644 --- a/public/app/plugins/panel/table/renderer.ts +++ b/public/app/plugins/panel/table/renderer.ts @@ -4,8 +4,6 @@ import _ from 'lodash'; import moment from 'moment'; import kbn from 'app/core/utils/kbn'; - - export class TableRenderer { formaters: any[]; colorState: any; @@ -26,27 +24,21 @@ export class TableRenderer { return _.first(style.colors); } - defaultCellFormater(escapeHtml = true) { - return function(v) { - if (v === null || v === void 0 || v === undefined) { - return ''; - } + defaultCellFormater(value) { + if (value === null || value === void 0 || value === undefined) { + return ''; + } - if (_.isArray(v)) { - v = v.join(', '); - } + if (_.isArray(value)) { + value = value.join(', '); + } - if (_.isString(v) && escapeHtml) { - v = encodeHtml(v); - } - - return v; - }; + return value; } createColumnFormater(style) { if (!style) { - return this.defaultCellFormater(); + return this.defaultCellFormater; } if (style.type === 'date') { @@ -69,7 +61,7 @@ export class TableRenderer { } if (_.isString(v)) { - return encodeHtml(v); + return v; } if (style.colorMode) { @@ -80,11 +72,7 @@ export class TableRenderer { }; } - if (style.type === 'string') { - return this.defaultCellFormater(style.escapeHtml); - } - - return this.defaultCellFormater(); + return this.defaultCellFormater; } formatColumnValue(colIndex, value) { @@ -102,12 +90,13 @@ export class TableRenderer { } } - this.formaters[colIndex] = this.defaultCellFormater(); + this.formaters[colIndex] = this.defaultCellFormater; return this.formaters[colIndex](value); } renderCell(columnIndex, value, addWidthHack = false) { value = this.formatColumnValue(columnIndex, value); + value = encodeHtml(value); var style = ''; if (this.colorState.cell) { style = ' style="background-color:' + this.colorState.cell + ';color: white"'; diff --git a/public/app/plugins/panel/table/specs/renderer_specs.ts b/public/app/plugins/panel/table/specs/renderer_specs.ts index 70dca26a0e8..e5c3d343435 100644 --- a/public/app/plugins/panel/table/specs/renderer_specs.ts +++ b/public/app/plugins/panel/table/specs/renderer_specs.ts @@ -41,12 +41,10 @@ describe('when rendering table', () => { { pattern: 'String', type: 'string', - escapeHtml: true, }, { pattern: 'UnescapedString', - type: 'string', - escapeHtml: false, + type: 'string' } ] }; @@ -98,11 +96,6 @@ describe('when rendering table', () => { expect(html).to.be('&breaking <br /> the <br /> row'); }); - it('string style with escape html false should return html', () => { - var html = renderer.renderCell(5, "&breaking
the
row"); - expect(html).to.be('&breaking
the
row'); - }); - it('undefined value should render as -', () => { var html = renderer.renderCell(3, undefined); expect(html).to.be('');