From a9a4fa7824632847cc172abc2e6e5392ef15db8d Mon Sep 17 00:00:00 2001 From: Jan Sprinz Date: Sat, 6 Mar 2021 18:01:09 +0100 Subject: [PATCH] Ensure plugin and provider exist when resolving remote_values, fixes #1624 --- src/core/plugins/index.js | 10 +++++++++- src/core/plugins/index.spec.js | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/core/plugins/index.js b/src/core/plugins/index.js index a8b22c91..0c4e439b 100644 --- a/src/core/plugins/index.js +++ b/src/core/plugins/index.js @@ -78,9 +78,17 @@ class PluginIndex { }); } + /** + * resolves remote values + * @returns {Promise} + */ remote_value(option) { return Promise.resolve(this.parsePluginId(option.remote_values)) - .then(([p, f]) => this.plugins[p][`remote_values__${f}`](option)) + .then(([p, f]) => + this.plugins[p] && this.plugins[p][`remote_values__${f}`] + ? this.plugins[p][`remote_values__${f}`](option) + : [] + ) .then(values => (option.values = values)); } diff --git a/src/core/plugins/index.spec.js b/src/core/plugins/index.spec.js index 3c7aec37..daf16f12 100644 --- a/src/core/plugins/index.spec.js +++ b/src/core/plugins/index.spec.js @@ -67,6 +67,20 @@ describe("PluginIndex", () => { pluginIndex.plugins.systemimage.remote_values__channels.mockRestore(); }); }); + it("should resolve empty on invalid plugin", () => { + return pluginIndex + .remote_value({ remote_values: { "systemimage:invalid": { a: "b" } } }) + .then(r => { + expect(r).toEqual([]); + }); + }); + it("should resolve empty on invalid provider", () => { + return pluginIndex + .remote_value({ remote_values: { "invalid:invalid": { a: "b" } } }) + .then(r => { + expect(r).toEqual([]); + }); + }); }); describe("getPluginArray()", () => { it("should return plugin array", () =>