From 008a59b004486053c07bc269a928da00e807bc74 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 26 Jul 2022 13:42:03 +0930 Subject: [PATCH] lightningd: ignore default if it's a literal 'null' JSON token. I wondered how `tests/plugins/dblog.py` worked, since it is supposed to fail unless the `dblog-file` arg is set: ``` @plugin.init() def init(configuration, options, plugin): if not plugin.get_option('dblog-file'): raise RpcError("No dblog-file specified") ``` But it was set to "null". That's because 'None' in python is turned into a literal JSON "null", and we take that as the default value. We also cleanup the popt->description double-assignment (a leftover from when this was optional). Signed-off-by: Rusty Russell Changelog-Fixed: plugins: setting the default value of a parameter to `null` is the same as not setting it (pyln plugins did this!). --- lightningd/plugin.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index f69258633..ea9fb5c75 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -940,7 +940,7 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer, if (strchr(popt->name, '|')) return tal_fmt(plugin, "Option \"name\" may not contain '|'"); - popt->description = NULL; + popt->description = json_strdup(popt, buffer, desctok); if (deptok) { if (!json_to_bool(buffer, deptok, &popt->deprecated)) return tal_fmt(plugin, @@ -981,7 +981,7 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer, "Only \"string\", \"int\", \"bool\", and \"flag\" options are supported"); } - if (defaulttok) { + if (defaulttok && !json_tok_is_null(buffer, defaulttok)) { popt->def = plugin_opt_value(popt, popt->type, json_strdup(tmpctx, buffer, defaulttok)); if (!popt->def) @@ -991,8 +991,6 @@ static const char *plugin_opt_add(struct plugin *plugin, const char *buffer, popt->type); } - if (!popt->description) - popt->description = json_strdup(popt, buffer, desctok); list_add_tail(&plugin->plugin_opts, &popt->list);