Skip to content

Commit

Permalink
Merge r1860152 from apr/trunk:
Browse files Browse the repository at this point in the history
  * Fix bug in apr_json_double_create().

git-svn-id: https://svn.apache.org/repos/asf/apr/apr-util/branches/1.7.x@1920373 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Ivan Zhakov committed Sep 1, 2024
1 parent c97cb8b commit d707c4e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion json/apr_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ apr_json_value_t *apr_json_double_create(apr_pool_t *pool, double dnumber)

if (json) {
json->type = APR_JSON_DOUBLE;
json->value.lnumber = dnumber;
json->value.dnumber = dnumber;
}

return json;
Expand Down
47 changes: 47 additions & 0 deletions test/testjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,52 @@ static void test_json_array_iterate(abts_case * tc, void *data)

}

static void test_json_create(abts_case* tc, void* data)
{
apr_json_value_t *json;
apr_status_t status;
apr_bucket_brigade *bb;
apr_bucket_alloc_t *ba;
char buf[1024];
apr_size_t len;

ba = apr_bucket_alloc_create(p);
bb = apr_brigade_create(p, ba);

json = apr_json_object_create(p);
apr_json_object_set(json, "null", APR_JSON_VALUE_STRING,
apr_json_null_create(p), p);

apr_json_object_set(json, "bool", APR_JSON_VALUE_STRING,
apr_json_boolean_create(p, 1), p);

apr_json_object_set(json, "double", APR_JSON_VALUE_STRING,
apr_json_double_create(p, 12.34), p);

apr_json_object_set(json, "long", APR_JSON_VALUE_STRING,
apr_json_long_create(p, 1234), p);

apr_json_object_set(json, "string", APR_JSON_VALUE_STRING,
apr_json_string_create(p, "str",
APR_JSON_VALUE_STRING),
p);

status = apr_json_encode(bb, NULL, NULL, json,
APR_JSON_FLAGS_WHITESPACE, p);

ABTS_INT_EQUAL(tc, APR_SUCCESS, status);

len = sizeof(buf);
status = apr_brigade_flatten(bb, buf, &len);
ABTS_INT_EQUAL(tc, APR_SUCCESS, status);
buf[len] = 0;

ABTS_STR_EQUAL(tc,
"{\"null\":null,\"bool\":true,\"double\":12.340000,"
"\"long\":1234,\"string\":\"str\"}",
buf);
}

abts_suite *testjson(abts_suite * suite)
{
suite = ADD_SUITE(suite);
Expand All @@ -241,6 +287,7 @@ abts_suite *testjson(abts_suite * suite)
abts_run_test(suite, test_json_overlay, NULL);
abts_run_test(suite, test_json_object_iterate, NULL);
abts_run_test(suite, test_json_array_iterate, NULL);
abts_run_test(suite, test_json_create, NULL);

return suite;
}

0 comments on commit d707c4e

Please sign in to comment.