Merge pull request #143 from chipdude/master

paper bag bug: json_string_set* functions should set the length too
This commit is contained in:
Petri Lehtinen 2013-10-03 22:36:34 -07:00
commit 8dc3233f3b
2 changed files with 31 additions and 4 deletions

View File

@ -723,6 +723,7 @@ int json_string_setn_nocheck(json_t *json, const char *value, size_t len)
string = json_to_string(json);
jsonp_free(string->value);
string->value = dup;
string->length = len;
return 0;
}

View File

@ -72,11 +72,22 @@ static void run_tests()
fail("json_string failed");
if(strcmp(json_string_value(value), "foo"))
fail("invalid string value");
if (json_string_length(value) != 3)
fail("invalid string length");
if(json_string_set(value, "bar"))
if(json_string_set(value, "barr"))
fail("json_string_set failed");
if(strcmp(json_string_value(value), "bar"))
if(strcmp(json_string_value(value), "barr"))
fail("invalid string value");
if (json_string_length(value) != 4)
fail("invalid string length");
if(json_string_setn(value, "hi\0ho", 5))
fail("json_string_set failed");
if(memcmp(json_string_value(value), "hi\0ho\0", 6))
fail("invalid string value");
if (json_string_length(value) != 5)
fail("invalid string length");
json_decref(value);
@ -94,11 +105,22 @@ static void run_tests()
fail("json_string_nocheck failed");
if(strcmp(json_string_value(value), "foo"))
fail("invalid string value");
if (json_string_length(value) != 3)
fail("invalid string length");
if(json_string_set_nocheck(value, "bar"))
if(json_string_set_nocheck(value, "barr"))
fail("json_string_set_nocheck failed");
if(strcmp(json_string_value(value), "bar"))
if(strcmp(json_string_value(value), "barr"))
fail("invalid string value");
if (json_string_length(value) != 4)
fail("invalid string length");
if(json_string_setn_nocheck(value, "hi\0ho", 5))
fail("json_string_set failed");
if(memcmp(json_string_value(value), "hi\0ho\0", 6))
fail("invalid string value");
if (json_string_length(value) != 5)
fail("invalid string length");
json_decref(value);
@ -108,11 +130,15 @@ static void run_tests()
fail("json_string_nocheck failed");
if(strcmp(json_string_value(value), "qu\xff"))
fail("invalid string value");
if (json_string_length(value) != 3)
fail("invalid string length");
if(json_string_set_nocheck(value, "\xfd\xfe\xff"))
fail("json_string_set_nocheck failed");
if(strcmp(json_string_value(value), "\xfd\xfe\xff"))
fail("invalid string value");
if (json_string_length(value) != 3)
fail("invalid string length");
json_decref(value);