@vaadin/vaadin-charts 6.3.4 → 6.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/src/vaadin-chart.js +105 -1
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "repository": "vaadin/vaadin-charts",
11
11
  "homepage": "https://vaadin.com/charts",
12
12
  "name": "@vaadin/vaadin-charts",
13
- "version": "6.3.4",
13
+ "version": "6.3.6",
14
14
  "main": "vaadin-chart.js",
15
15
  "author": "Vaadin Ltd",
16
16
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -32,6 +32,7 @@
32
32
  "dependencies": {
33
33
  "highcharts": "6.1.4",
34
34
  "@polymer/polymer": "^3.0.0",
35
+ "dompurify": "2.0.5",
35
36
  "@vaadin/vaadin-themable-mixin": "^1.5.2",
36
37
  "@vaadin/vaadin-license-checker": "^2.1.0",
37
38
  "@vaadin/vaadin-element-mixin": "^2.3.2"
@@ -31,6 +31,107 @@ import 'highcharts/js/es-modules/masters/modules/heatmap.src.js';
31
31
  import 'highcharts/js/es-modules/masters/modules/solid-gauge.src.js';
32
32
  import 'highcharts/js/es-modules/masters/modules/treemap.src.js';
33
33
  import 'highcharts/js/es-modules/masters/modules/no-data-to-display.src.js';
34
+ import DOMPurify from 'dompurify';
35
+ window.sanitizeHighchartsAPI = (Highcharts, DOMPurify) => {
36
+ var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
37
+ if (isIE11) {
38
+ DOMPurify.setConfig({
39
+ FORCE_BODY: true,
40
+ });
41
+ }
42
+ // This function will recursively sanitize all strings in the options object
43
+ // Source: https://jsfiddle.net/highcharts/zd3wcm5L/
44
+ function stripHTMLRecurse(obj) {
45
+ if (obj === null || obj === undefined) {
46
+ return obj;
47
+ }
48
+
49
+ if (typeof obj === 'string') {
50
+ return DOMPurify.sanitize(obj);
51
+ }
52
+
53
+ if (typeof obj !== 'object') {
54
+ return obj;
55
+ }
56
+
57
+ Object.keys(obj).forEach((key) => {
58
+ if (typeof obj[key] === 'string') {
59
+ obj[key] = DOMPurify.sanitize(obj[key]);
60
+ } else if (Array.isArray(obj[key])) {
61
+ obj[key].forEach((item, i) => {
62
+ obj[key][i] = stripHTMLRecurse(item);
63
+ });
64
+ } else if (typeof obj[key] === 'object') {
65
+ obj[key] = stripHTMLRecurse(obj[key]);
66
+ }
67
+ });
68
+ return obj;
69
+ }
70
+
71
+ const update = Highcharts.Chart.prototype.update;
72
+ Highcharts.Chart.prototype.update = function(
73
+ options,
74
+ redraw,
75
+ oneToOne,
76
+ animation
77
+ ) {
78
+ options = stripHTMLRecurse(options);
79
+ return update.call(this, options, redraw, oneToOne, animation);
80
+ };
81
+
82
+ const newChart = Highcharts.chart;
83
+ Highcharts.chart = function(renderTo, options, callback) {
84
+ options = stripHTMLRecurse(options);
85
+ return newChart.call(this, renderTo, options, callback);
86
+ };
87
+
88
+ const newHighstock = Highcharts.stockChart;
89
+ Highcharts.stockChart = function(renderTo, options, callback) {
90
+ options = stripHTMLRecurse(options);
91
+ return newHighstock.call(this, renderTo, options, callback);
92
+ };
93
+
94
+ const axisUpdate = Highcharts.Axis.prototype.update;
95
+ Highcharts.Axis.prototype.update = function(options, redraw) {
96
+ options = stripHTMLRecurse(options);
97
+ return axisUpdate.call(this, options, redraw);
98
+ };
99
+
100
+ const seriesUpdate = Highcharts.Series.prototype.update;
101
+ Highcharts.Series.prototype.update = function(options, redraw) {
102
+ options = stripHTMLRecurse(options);
103
+ return seriesUpdate.call(this, options, redraw);
104
+ };
105
+
106
+ const legendUpdate = Highcharts.Legend.prototype.update;
107
+ Highcharts.Legend.prototype.update = function(options, redraw) {
108
+ options = stripHTMLRecurse(options);
109
+ return legendUpdate.call(this, options, redraw);
110
+ };
111
+
112
+ const addCredits = Highcharts.Chart.prototype.addCredits;
113
+ Highcharts.Chart.prototype.addCredits = function(credits) {
114
+ credits = stripHTMLRecurse(credits);
115
+ return addCredits.call(this, credits);
116
+ };
117
+
118
+ const setTitle = Highcharts.Chart.prototype.setTitle;
119
+ Highcharts.Chart.prototype.setTitle = function(
120
+ titleOptions,
121
+ subtitleOptions,
122
+ redraw
123
+ ) {
124
+ titleOptions = stripHTMLRecurse(titleOptions);
125
+ subtitleOptions = stripHTMLRecurse(subtitleOptions);
126
+ return setTitle.call(this, titleOptions, subtitleOptions, redraw);
127
+ };
128
+
129
+ const tooltipUpdate = Highcharts.Tooltip.prototype.update;
130
+ Highcharts.Tooltip.prototype.update = function(options) {
131
+ options = stripHTMLRecurse(options);
132
+ return tooltipUpdate.call(this, options);
133
+ };
134
+ };
34
135
 
35
136
  /** @private */
36
137
  // eslint-disable-next-line no-unused-vars
@@ -89,6 +190,9 @@ if (!PolymerElement) {
89
190
  console.warn(`Unexpected Polymer version ${Polymer.version} is used, expected v2.0.0 or later.`);
90
191
  }
91
192
 
193
+ // eslint-disable-next-line no-undef
194
+ sanitizeHighchartsAPI(Highcharts, DOMPurify);
195
+
92
196
  /**
93
197
  * `<vaadin-chart>` is a Web Component for creating high quality charts.
94
198
  *
@@ -380,7 +484,7 @@ class ChartElement extends ElementMixin(ThemableMixin(PolymerElement)) {
380
484
  }
381
485
 
382
486
  static get version() {
383
- return '6.3.4';
487
+ return '6.3.6';
384
488
  }
385
489
 
386
490
  static get cvdlName() {