]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Add sanity checks for scale options (#9624)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Mon, 6 Sep 2021 04:51:18 +0000 (07:51 +0300)
committerGitHub <noreply@github.com>
Mon, 6 Sep 2021 04:51:18 +0000 (07:51 +0300)
src/core/core.config.js
test/specs/core.controller.tests.js

index 18fe50a1e1914a39490fd4c1f46067418ba2205e..1523eb5c5c9b4f23bb39b6a7c07982e4e21c7c4c 100644 (file)
@@ -48,6 +48,12 @@ function mergeScaleConfig(config, options) {
   // First figure out first scale id's per axis.
   Object.keys(configScales).forEach(id => {
     const scaleConf = configScales[id];
+    if (!isObject(scaleConf)) {
+      return console.error(`Invalid scale configuration for scale: ${id}`);
+    }
+    if (scaleConf._proxy) {
+      return console.warn(`Ignoring resolver passed as options for scale: ${id}`);
+    }
     const axis = determineAxis(id, scaleConf);
     const defaultId = getDefaultScaleIDFromAxis(axis, chartIndexAxis);
     const defaultScaleOptions = chartDefaults.scales || {};
index 809b721d9d4cf2c93b9e65d3c19e1c956b5f3988..cb4eba08c071a2b4dd0951d62790450f096b4777 100644 (file)
@@ -498,6 +498,49 @@ describe('Chart', function() {
       expect(Chart.defaults.scales.linear._jasmineCheck).not.toBeDefined();
       expect(Chart.defaults.scales.category._jasmineCheck).not.toBeDefined();
     });
+
+    it('should ignore proxy passed as scale options', function() {
+      let failure = false;
+      const chart = acquireChart({
+        type: 'line',
+        data: [],
+        options: {
+          scales: {
+            x: {
+              grid: {
+                color: ctx => {
+                  if (!ctx.tick) {
+                    failure = true;
+                  }
+                }
+              }
+            }
+          }
+        }
+      });
+      chart.options.scales = {
+        x: chart.options.scales.x,
+        y: {
+          type: 'linear',
+          position: 'right'
+        }
+      };
+      chart.update();
+      expect(failure).toEqual(false);
+    });
+
+    it('should ignore array passed as scale options', function() {
+      const chart = acquireChart({
+        type: 'line',
+        data: [],
+        options: {
+          scales: {
+            xAxes: [{id: 'xAxes', type: 'category'}]
+          }
+        }
+      });
+      expect(chart.scales.xAxes).not.toBeDefined();
+    });
   });
 
   describe('Updating options', function() {