From: stockiNail Date: Thu, 15 Sep 2022 16:12:35 +0000 (+0200) Subject: Provide an empty object when the target of the resolver is undefined (#10655) X-Git-Tag: v4.0.0~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4e106cc9cf19a273e5485ffaf6158f663e65717;p=thirdparty%2FChart.js.git Provide an empty object when the target of the resolver is undefined (#10655) * Provide an empty object when the target of the proxy is undefined * changes check on subGetTarget function * adds test case * fixes lint --- diff --git a/src/helpers/helpers.config.js b/src/helpers/helpers.config.js index 058739d94..0b2292222 100644 --- a/src/helpers/helpers.config.js +++ b/src/helpers/helpers.config.js @@ -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) { diff --git a/test/specs/core.plugin.tests.js b/test/specs/core.plugin.tests.js index 836ead0fc..4b06e6f43 100644 --- a/test/specs/core.plugin.tests.js +++ b/test/specs/core.plugin.tests.js @@ -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({