diff --git a/parson.c b/parson.c index 04d2f18..fd1b51c 100644 --- a/parson.c +++ b/parson.c @@ -972,13 +972,13 @@ JSON_Value * json_value_init_array(void) { } JSON_Value * json_value_init_string(const char *string) { - char *processed_copy = NULL; + char *copy = NULL; if (string == NULL) return NULL; - processed_copy = process_string(string, strlen(string)); - if (processed_copy == NULL) + copy = parson_strdup(string); + if (copy == NULL) return NULL; - return json_value_init_string_no_copy(processed_copy); + return json_value_init_string_no_copy(copy); } JSON_Value * json_value_init_number(double number) { diff --git a/tests.c b/tests.c index 227e08b..0b47732 100644 --- a/tests.c +++ b/tests.c @@ -264,9 +264,10 @@ void test_suite_5(void) { TEST(json_object_dotset_string(obj, "favorites.sport", "running") == JSONSuccess); TEST(json_object_dotset_string(obj, "favorites.fruit", "apple") == JSONSuccess); TEST(json_object_dotremove(obj, "favorites.fruit") == JSONSuccess); - TEST(json_object_set_string(obj, "utf string", "\\u006corem\\u0020ipsum") == JSONSuccess); + TEST(json_object_set_string(obj, "utf string", "lorem ipsum") == JSONSuccess); TEST(json_object_set_string(obj, "utf-8 string", "あいうえお") == JSONSuccess); - TEST(json_object_set_string(obj, "surrogate string", "lorem\\uD834\\uDD1Eipsum\\uD834\\uDF67lorem") == JSONSuccess); + TEST(json_object_set_string(obj, "surrogate string", "lorem𝄞ipsum𝍧lorem") == JSONSuccess); + TEST(json_object_set_string(obj, "windows path", "C:\\Windows\\Path") == JSONSuccess); TEST(json_value_equals(val_from_file, val)); TEST(json_object_set_string(obj, NULL, "") == JSONFailure); diff --git a/tests/test_5.txt b/tests/test_5.txt index 6e71331..fc71450 100644 --- a/tests/test_5.txt +++ b/tests/test_5.txt @@ -10,5 +10,6 @@ }, "utf string" : "\u006corem\u0020ipsum", "utf-8 string": "あいうえお", - "surrogate string": "lorem\uD834\uDD1Eipsum\uD834\uDF67lorem" + "surrogate string": "lorem\uD834\uDD1Eipsum\uD834\uDF67lorem", + "windows path": "C:\\Windows\\Path" } \ No newline at end of file