]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Ensure getPrototypeOf will not crash on plugin options with no scopes (#9431)
authorEvert Timberg <evert.timberg+github@gmail.com>
Sat, 24 Jul 2021 03:40:03 +0000 (23:40 -0400)
committerGitHub <noreply@github.com>
Sat, 24 Jul 2021 03:40:03 +0000 (06:40 +0300)
* Ensure getPrototypeOf will not crash on plugin options with no scopes

* Code review improvements

src/core/core.config.js
test/specs/core.controller.tests.js

index 255699bdf527c36dd67fa80cd3330168587b2679..18fe50a1e1914a39490fd4c1f46067418ba2205e 100644 (file)
@@ -281,6 +281,9 @@ export default class Config {
     });
 
     const array = Array.from(scopes);
+    if (array.length === 0) {
+      array.push(Object.create(null));
+    }
     if (keysCached.has(keyLists)) {
       cache.set(keyLists, array);
     }
index ac0479b202b768a37986a43265143d2802441c63..5072537e97575ee644d43ac118f4198095488c35 100644 (file)
@@ -1707,6 +1707,23 @@ describe('Chart', function() {
         'before-0', 'after-0'
       ]);
     });
+
+    it('should not crash when accessing options of a blank inline plugin', function() {
+      var chart = window.acquireChart({
+        type: 'line',
+        data: {datasets: [{}]},
+        plugins: [{}],
+      });
+
+      function iterateOptions() {
+        for (const plugin of chart._plugins._init) {
+          // triggering bug https://github.com/chartjs/Chart.js/issues/9368
+          expect(Object.getPrototypeOf(plugin.options)).toBeNull();
+        }
+      }
+
+      expect(iterateOptions).not.toThrow();
+    });
   });
 
   describe('metasets', function() {