mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
json: escape and unescape invalid unicode chars
This commit is contained in:
parent
22f6e8e36d
commit
f41de50b28
2 changed files with 25 additions and 2 deletions
|
|
@ -154,6 +154,7 @@ static void test_encode(void)
|
|||
char dst[1024];
|
||||
char dst4[4];
|
||||
char dst6[6];
|
||||
char result[1024];
|
||||
spa_assert(spa_json_encode_string(dst, sizeof(dst), "test") == 6);
|
||||
spa_assert(strcmp(dst, "\"test\"") == 0);
|
||||
spa_assert(spa_json_encode_string(dst4, sizeof(dst4), "test") == 6);
|
||||
|
|
@ -162,6 +163,10 @@ static void test_encode(void)
|
|||
spa_assert(strncmp(dst6, "\"test\"", 6) == 0);
|
||||
spa_assert(spa_json_encode_string(dst, sizeof(dst), "test\"\n\r \t\b\f\'") == 20);
|
||||
spa_assert(strcmp(dst, "\"test\\\"\\n\\r \\t\\b\\f'\"") == 0);
|
||||
spa_assert(spa_json_encode_string(dst, sizeof(dst), "\x04\x05\x1f\x20\x01\x7f\x90") == 29);
|
||||
spa_assert(strcmp(dst, "\"\\u0004\\u0005\\u001f \\u0001\x7f\x90\"") == 0);
|
||||
spa_assert(spa_json_parse_string(dst, sizeof(dst), result) == 1);
|
||||
spa_assert(strcmp(result, "\x04\x05\x1f\x20\x01\x7f\x90") == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue