]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Provide an empty object when the target of the resolver is undefined (#10655)
authorstockiNail <stocki.nail@gmail.com>
Thu, 15 Sep 2022 16:12:35 +0000 (18:12 +0200)
committerGitHub <noreply@github.com>
Thu, 15 Sep 2022 16:12:35 +0000 (12:12 -0400)
* Provide an empty object when the target of the proxy is undefined

* changes check on subGetTarget function

* adds test case

* fixes lint

src/helpers/helpers.config.js
test/specs/core.plugin.tests.js

index 058739d94c6114f48cb3da3a25e56c7b18a2fe0d..0b2292222943b8dcf13d2589f4b4c36bec83b544 100644 (file)
@@ -307,7 +307,7 @@ function subGetTarget(resolver, prop, value) {
     // For array of objects, the object is used to store updated values
     return value;
   }
-  return target;
+  return target || {};
 }
 
 function _resolveWithPrefixes(prop, prefixes, scopes, proxy) {
index 836ead0fca3fa66357adb5f672ff2157a3eea04c..4b06e6f432b5d1d79042f1ee15592d9b0433128e 100644 (file)
@@ -351,6 +351,42 @@ describe('Chart.plugins', function() {
       expect(plugin.hook.calls.first().args[2]).toEqualOptions({bar: 'bar'});
     });
 
+    // https://github.com/chartjs/Chart.js/issues/10654
+    it('should resolve options even if some subnodes are set as undefined', function() {
+      var runtimeOptions;
+      var plugin = {
+        id: 'a',
+        afterUpdate: function(chart, args, options) {
+          options.l1.l2.l3.display = true;
+          runtimeOptions = options;
+        },
+        defaults: {
+          l1: {
+            l2: {
+              l3: {
+                display: false
+              }
+            }
+          }
+        }
+      };
+      window.acquireChart({
+        plugins: [plugin],
+        options: {
+          plugins: {
+            a: {
+              l1: {
+                l2: undefined
+              }
+            },
+          }
+        },
+      });
+
+      expect(runtimeOptions.l1.l2.l3.display).toBe(true);
+      Chart.unregister(plugin);
+    });
+
     it('should disable all plugins', function() {
       var plugin = {id: 'a', hook: function() {}};
       var chart = window.acquireChart({