Changeset

9117:a19fdc6e4f09

util.pubsub: Apply defaults metatable before config check (thanks pep.) Makes it so that the callback sees the default if it’s not in the form, which makes it easier to validate.
author Kim Alvefur <zash@zash.se>
date Sun, 05 Aug 2018 15:17:00 +0200
parents 9116:9f36f5c14545
children 9118:70f34c663fb3
files util/pubsub.lua
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util/pubsub.lua	Sun Aug 05 02:01:58 2018 +0200
+++ b/util/pubsub.lua	Sun Aug 05 15:17:00 2018 +0200
@@ -565,6 +565,8 @@
 		return false, "item-not-found";
 	end
 
+	setmetatable(new_config, {__index=self.node_defaults})
+
 	if self.config.check_node_config then
 		local ok = self.config.check_node_config(node, actor, new_config);
 		if not ok then
@@ -573,7 +575,7 @@
 	end
 
 	local old_config = node_obj.config;
-	node_obj.config = setmetatable(new_config, {__index=self.node_defaults});
+	node_obj.config = new_config;
 
 	if self.config.nodestore then
 		local ok, err = save_node_to_store(self, node_obj);