I presume you are subscribed to the commits list, which broadcasts our CI
results?
testjson : FAILED 1 of 7Line 62: expected something other
than <{ "Image" : { "Width" : 800 , "IDs" : [116, 943, 234,
38793], "Title" : "View from 15th Floor", "Animated" : false,
"Thumbnail" : { "Height" : 125, "Width" : 100, "Url" :
"http://www.example.com/image/481989943" }, "Height" : 600
}}>, but saw <{"Image": {"Width": 800 ,"IDs": [116, 943, 234,
38793],"Title": "View from 15th Floor","Animated": false,"Thumbnail":
{"Height": 125,"Width": 100,"Url":
"http://www.example.com/image/481989943" },"Height": 600 }}q�k�
>Failed Tests Total Fail Failed %
===================================================
testjson 7 1 14.29%
On Fri, Aug 31, 2018 at 7:25 AM, <[email protected]> wrote:
> Author: ylavic
> Date: Fri Aug 31 12:25:34 2018
> New Revision: 1839755
>
> URL: http://svn.apache.org/viewvc?rev=1839755&view=rev
> Log:
> apr_json: object keys are strings.
>
> Make this clear in the API by requiring a usual string in
> apr_json_object_set()
> and creating the apr_json_string_t from it.
>
> It's also more user friendly as otherwise apr_json_string_create() is to be
> used when setting an entry.
>
> Also, axe the 'pool' arg from apr_json_array_add() since it's not needed.
>
> Modified:
> apr/apr/trunk/include/apr_json.h
> apr/apr/trunk/json/apr_json.c
> apr/apr/trunk/json/apr_json_decode.c
>
> Modified: apr/apr/trunk/include/apr_json.h
> URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_
> json.h?rev=1839755&r1=1839754&r2=1839755&view=diff
> ============================================================
> ==================
> --- apr/apr/trunk/include/apr_json.h (original)
> +++ apr/apr/trunk/include/apr_json.h Fri Aug 31 12:25:34 2018
> @@ -178,7 +178,7 @@ struct apr_json_object_t {
> * Use apr_json_array_create() to allocate.
> */
> struct apr_json_array_t {
> - /** The key value pairs in the object are in this list */
> + /** The values in the array are in this list */
> APR_RING_HEAD(apr_json_array_list_t, apr_json_value_t) list;
> /** Array of JSON objects */
> apr_array_header_t *array;
> @@ -271,8 +271,9 @@ APR_DECLARE(apr_json_value_t *)
> /**
> * Associate a value with a key in a JSON object.
> * @param obj The JSON object.
> - * @param key Pointer to the key string, including any whitespace
> - * required.
> + * @param key Pointer to the key.
> + * @param klen Length of the key, or APR_JSON_VALUE_STRING if NUL
> + * terminated.
> * @param val Value to associate with the key.
> * @param pool Pool to use.
> * @return APR_SUCCESS on success, APR_EINVAL if the key is
> @@ -280,20 +281,19 @@ APR_DECLARE(apr_json_value_t *)
> * @remark If the value is NULL the key value pair is deleted.
> */
> APR_DECLARE(apr_status_t) apr_json_object_set(apr_json_value_t *obj,
> - apr_json_value_t *key, apr_json_value_t *val,
> - apr_pool_t *pool) __attribute__((nonnull(1, 4)));
> + const char *key, apr_ssize_t klen, apr_json_value_t *val,
> + apr_pool_t *pool) __attribute__((nonnull(1, 2, 5)));
>
> /**
> * Look up the value associated with a key in a JSON object.
> * @param obj The JSON object.
> * @param key Pointer to the key.
> * @param klen Length of the key, or APR_JSON_VALUE_STRING if NUL
> - * terminated.
> + * terminated.
> * @return Returns NULL if the key is not present.
> */
> -APR_DECLARE(apr_json_kv_t *)
> - apr_json_object_get(apr_json_value_t *obj, const char *key,
> - apr_ssize_t klen)
> +APR_DECLARE(apr_json_kv_t *) apr_json_object_get(apr_json_value_t *obj,
> + const char *key, apr_ssize_t klen)
> __attribute__((nonnull(1, 2)));
>
> /**
> @@ -325,13 +325,12 @@ APR_DECLARE(apr_json_kv_t *) apr_json_ob
> * Add the value to the end of this array.
> * @param arr The JSON array.
> * @param val Value to add to the array.
> - * @param pool Pool to use.
> * @return APR_SUCCESS on success, APR_EINVAL if the array value is not
> * an APR_JSON_ARRAY.
> */
> APR_DECLARE(apr_status_t) apr_json_array_add(apr_json_value_t *arr,
> - apr_json_value_t *val, apr_pool_t *pool)
> - __attribute__((nonnull(1, 2, 3)));
> + apr_json_value_t *val)
> + __attribute__((nonnull(1, 2)));
>
> /**
> * Look up the value associated with a key in a JSON object.
>
> Modified: apr/apr/trunk/json/apr_json.c
> URL: http://svn.apache.org/viewvc/apr/apr/trunk/json/apr_json.c?
> rev=1839755&r1=1839754&r2=1839755&view=diff
> ============================================================
> ==================
> --- apr/apr/trunk/json/apr_json.c (original)
> +++ apr/apr/trunk/json/apr_json.c Fri Aug 31 12:25:34 2018
> @@ -129,25 +129,23 @@ apr_json_value_t *apr_json_null_create(a
> return json;
> }
>
> -apr_status_t apr_json_object_set(apr_json_value_t *object,
> apr_json_value_t *key,
> - apr_json_value_t *val, apr_pool_t *pool)
> +apr_status_t apr_json_object_set(apr_json_value_t *object, const char
> *key,
> + apr_ssize_t klen, apr_json_value_t *val, apr_pool_t *pool)
> {
> apr_json_kv_t *kv;
> apr_hash_t *hash;
>
> - if (object->type != APR_JSON_OBJECT || !key
> - || key->type != APR_JSON_STRING) {
> + if (object->type != APR_JSON_OBJECT) {
> return APR_EINVAL;
> }
>
> hash = object->value.object->hash;
>
> - kv = apr_hash_get(hash, key->value.string.p, key->value.string.len);
> + kv = apr_hash_get(hash, key, klen);
>
> if (!val) {
> if (kv) {
> - apr_hash_set(hash, key->value.string.p, key->value.string.len,
> - NULL);
> + apr_hash_set(hash, key, klen, NULL);
> APR_RING_REMOVE((kv), link);
> }
> return APR_SUCCESS;
> @@ -157,11 +155,10 @@ apr_status_t apr_json_object_set(apr_jso
> kv = apr_palloc(pool, sizeof(apr_json_kv_t));
> APR_RING_ELEM_INIT(kv, link);
> APR_JSON_OBJECT_INSERT_TAIL(object->value.object, kv);
> - apr_hash_set(hash, key->value.string.p, key->value.string.len,
> - kv);
> + kv->k = apr_json_string_create(pool, key, klen);
> + apr_hash_set(hash, kv->k->value.string.p,
> kv->k->value.string.len, kv);
> }
>
> - kv->k = key;
> kv->v = val;
>
> return APR_SUCCESS;
> @@ -212,8 +209,7 @@ apr_json_kv_t *apr_json_object_next(apr_
> }
> }
>
> -apr_status_t apr_json_array_add(apr_json_value_t *arr,
> - apr_json_value_t *val, apr_pool_t *pool)
> +apr_status_t apr_json_array_add(apr_json_value_t *arr, apr_json_value_t
> *val)
> {
> apr_array_header_t *array;
>
> @@ -316,7 +312,8 @@ apr_json_value_t *apr_json_overlay(apr_p
> if (!apr_hash_get(overlay->value.object->hash,
> kv->k->value.string.p,
> kv->k->value.string.len)) {
>
> - apr_json_object_set(res, kv->k, kv->v, p);
> + apr_json_object_set(res, kv->k->value.string.p,
> + kv->k->value.string.len, kv->v, p);
>
> }
> else if (APR_JSON_FLAGS_STRICT & flags) {
> @@ -329,7 +326,8 @@ apr_json_value_t *apr_json_overlay(apr_p
> kv != APR_RING_SENTINEL(&(overlay->value.object)->list,
> apr_json_kv_t, link);
> kv = APR_RING_NEXT((kv), link)) {
>
> - apr_json_object_set(res, kv->k, kv->v, p);
> + apr_json_object_set(res, kv->k->value.string.p,
> + kv->k->value.string.len, kv->v, p);
>
> }
>
>
> Modified: apr/apr/trunk/json/apr_json_decode.c
> URL: http://svn.apache.org/viewvc/apr/apr/trunk/json/apr_json_
> decode.c?rev=1839755&r1=1839754&r2=1839755&view=diff
> ============================================================
> ==================
> --- apr/apr/trunk/json/apr_json_decode.c (original)
> +++ apr/apr/trunk/json/apr_json_decode.c Fri Aug 31 12:25:34 2018
> @@ -390,8 +390,7 @@ static apr_status_t apr_json_decode_arra
> return status;
> }
>
> - if (APR_SUCCESS
> - != (status = apr_json_array_add(array, element,
> self->pool))) {
> + if (APR_SUCCESS != (status = apr_json_array_add(array, element)))
> {
> return status;
> }
>
> @@ -501,7 +500,8 @@ static apr_status_t apr_json_decode_obje
> if ((status = apr_json_decode_value(self, &value)))
> goto out;
>
> - apr_json_object_set(json, key, value, self->pool);
> + apr_json_object_set(json, key->value.string.p,
> key->value.string.len,
> + value, self->pool);
>
> if (self->p == self->e) {
> status = APR_EOF;
>
>
>