diff options
author | jobol <jose.bollo@iot.bzh> | 2018-05-14 11:36:22 +0200 |
---|---|---|
committer | jobol <jose.bollo@iot.bzh> | 2018-05-14 11:36:22 +0200 |
commit | 4b711e94452d4ef99f6ae7048af55fb03310b3cd (patch) | |
tree | ba791a7238179f76221dd2e850d5826e480e8da8 | |
parent | f8bd2bbcf385512cb8d111ac217812903ac87269 (diff) |
wrap-json: Accept null as valid base64
Signed-off-by: jobol <jose.bollo@iot.bzh>
-rw-r--r-- | wrap-json.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/wrap-json.c b/wrap-json.c index 11fdd8c..6978c25 100644 --- a/wrap-json.c +++ b/wrap-json.c @@ -665,15 +665,22 @@ static int vunpack(struct json_object *object, const char *desc, va_list args, i pz = va_arg(args, size_t *); } if (!ignore) { - if (!json_object_is_type(obj, json_type_string)) - goto missfit; - if (store && py && pz) { - rc = decode_base64( - json_object_get_string(obj), - (size_t)json_object_get_string_len(obj), - py, pz, c == 'y'); - if (rc) - goto error; + if (obj == NULL) { + if (store && py && pz) { + *py = NULL; + *pz = 0; + } + } else { + if (!json_object_is_type(obj, json_type_string)) + goto missfit; + if (store && py && pz) { + rc = decode_base64( + json_object_get_string(obj), + (size_t)json_object_get_string_len(obj), + py, pz, c == 'y'); + if (rc) + goto error; + } } } break; @@ -1133,6 +1140,8 @@ int main() U("{\"foo\":42}", "{s?isi!}", "baz", &xi[0], "foo", &xi[1]); U("\"Pz8_Pz8_P2hlbGxvPj4-Pj4-Pg\"", "y", &xy[0], &xz[0]); + U("\"\"", "y", &xy[0], &xz[0]); + U("null", "y", &xy[0], &xz[0]); U("{\"foo\":\"Pz8_Pz8_P2hlbGxvPj4-Pj4-Pg\"}", "{s?y}", "foo", &xy[0], &xz[0]); U("{\"foo\":\"\"}", "{s?y}", "foo", &xy[0], &xz[0]); U("{}", "{s?y}", "foo", &xy[0], &xz[0]); |