json: beef up strv parser to also accept a single string instead of an array of strings

Let's be permissive in what we accept and take a single string instead
of an array of strings, when a string is requested, too.
This commit is contained in:
Lennart Poettering 2019-01-03 12:19:31 +01:00
parent 95244ceb9c
commit 07737617a1

View file

@ -3420,6 +3420,16 @@ int json_dispatch_strv(const char *name, JsonVariant *variant, JsonDispatchFlags
return 0;
}
/* Let's be flexible here: accept a single string in place of a single-item array */
if (json_variant_is_string(variant)) {
l = strv_new(json_variant_string(variant));
if (!l)
return log_oom();
strv_free_and_replace(*s, l);
return 0;
}
if (!json_variant_is_array(variant))
return json_log(variant, SYNTHETIC_ERRNO(EINVAL), flags, "JSON field '%s' is not an array.", strna(name));