mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-26 21:04:24 +08:00
Merge pull request #447 from Alanscut/fix_encode_string_as_pointer
Fix encode_string_as_pointer
This commit is contained in:
commit
1be85ff26d
@ -173,13 +173,14 @@ static void encode_string_as_pointer(unsigned char *destination, const unsigned
|
|||||||
{
|
{
|
||||||
if (source[0] == '/')
|
if (source[0] == '/')
|
||||||
{
|
{
|
||||||
|
destination[0] = '~';
|
||||||
destination[1] = '1';
|
destination[1] = '1';
|
||||||
destination++;
|
destination++;
|
||||||
}
|
}
|
||||||
else if (source[0] == '~')
|
else if (source[0] == '~')
|
||||||
{
|
{
|
||||||
destination[0] = '~';
|
destination[0] = '~';
|
||||||
destination[1] = '1';
|
destination[1] = '0';
|
||||||
destination++;
|
destination++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -90,6 +90,10 @@ static void misc_tests(void)
|
|||||||
/* Misc tests */
|
/* Misc tests */
|
||||||
int numbers[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
int numbers[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||||
cJSON *object = NULL;
|
cJSON *object = NULL;
|
||||||
|
cJSON *object1 = NULL;
|
||||||
|
cJSON *object2 = NULL;
|
||||||
|
cJSON *object3 = NULL;
|
||||||
|
cJSON *object4 = NULL;
|
||||||
cJSON *nums = NULL;
|
cJSON *nums = NULL;
|
||||||
cJSON *num6 = NULL;
|
cJSON *num6 = NULL;
|
||||||
char *pointer = NULL;
|
char *pointer = NULL;
|
||||||
@ -112,7 +116,23 @@ static void misc_tests(void)
|
|||||||
TEST_ASSERT_EQUAL_STRING("", pointer);
|
TEST_ASSERT_EQUAL_STRING("", pointer);
|
||||||
free(pointer);
|
free(pointer);
|
||||||
|
|
||||||
|
object1 = cJSON_CreateObject();
|
||||||
|
object2 = cJSON_CreateString("m~n");
|
||||||
|
cJSON_AddItemToObject(object1, "m~n", object2);
|
||||||
|
pointer = cJSONUtils_FindPointerFromObjectTo(object1, object2);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("/m~0n",pointer);
|
||||||
|
free(pointer);
|
||||||
|
|
||||||
|
object3 = cJSON_CreateObject();
|
||||||
|
object4 = cJSON_CreateString("m/n");
|
||||||
|
cJSON_AddItemToObject(object3, "m/n", object4);
|
||||||
|
pointer = cJSONUtils_FindPointerFromObjectTo(object3, object4);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("/m~1n",pointer);
|
||||||
|
free(pointer);
|
||||||
|
|
||||||
cJSON_Delete(object);
|
cJSON_Delete(object);
|
||||||
|
cJSON_Delete(object1);
|
||||||
|
cJSON_Delete(object3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sort_tests(void)
|
static void sort_tests(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user