mirror of
https://github.com/kgabis/parson.git
synced 2024-11-24 06:05:29 +00:00
Bugfix in parsing escaped characters (+ additional tests to prevent this bug in future).
Thanks to Joseph Werle for bringing attention to it.
This commit is contained in:
parent
c707051778
commit
6e9e934b5a
17
parson.c
17
parson.c
@ -437,12 +437,14 @@ static const char * get_processed_string(const char **string) {
|
||||
if (*unprocessed_ptr == '\\') {
|
||||
unprocessed_ptr++;
|
||||
switch (*unprocessed_ptr) {
|
||||
case '\"': case '\\': case '/': break;
|
||||
case 'b': *processed_ptr = '\b'; break;
|
||||
case 'f': *processed_ptr = '\f'; break;
|
||||
case 'n': *processed_ptr = '\n'; break;
|
||||
case 'r': *processed_ptr = '\r'; break;
|
||||
case 't': *processed_ptr = '\t'; break;
|
||||
case '\"': *processed_ptr = '\"'; break;
|
||||
case '\\': *processed_ptr = '\\'; break;
|
||||
case '/': *processed_ptr = '/'; break;
|
||||
case 'b': *processed_ptr = '\b'; break;
|
||||
case 'f': *processed_ptr = '\f'; break;
|
||||
case 'n': *processed_ptr = '\n'; break;
|
||||
case 'r': *processed_ptr = '\r'; break;
|
||||
case 't': *processed_ptr = '\t'; break;
|
||||
case 'u':
|
||||
if (parse_utf_16(&processed_ptr, &unprocessed_ptr) == ERROR) {
|
||||
parson_free(output);
|
||||
@ -460,7 +462,8 @@ static const char * get_processed_string(const char **string) {
|
||||
} else {
|
||||
*processed_ptr = *unprocessed_ptr;
|
||||
}
|
||||
processed_ptr++, unprocessed_ptr++;
|
||||
processed_ptr++;
|
||||
unprocessed_ptr++;
|
||||
}
|
||||
*processed_ptr = '\0';
|
||||
if (try_realloc((void**)&output, strlen(output) + 1) == ERROR)
|
||||
|
2
tests.c
2
tests.c
@ -135,6 +135,8 @@ void test_suite_2(JSON_Value *root_value) {
|
||||
|
||||
TEST(STREQ(json_object_get_string(root_object, "/**/"), "comment"));
|
||||
TEST(STREQ(json_object_get_string(root_object, "//"), "comment"));
|
||||
TEST(STREQ(json_object_get_string(root_object, "url"), "https://www.example.com/search?q=12345"));
|
||||
TEST(STREQ(json_object_get_string(root_object, "escaped chars"), "\" \\ /"));
|
||||
}
|
||||
|
||||
void test_suite_2_no_comments(void) {
|
||||
|
@ -23,5 +23,6 @@
|
||||
"*/" : null,
|
||||
"/**/" : "comment",
|
||||
"//" : "comment",
|
||||
"#" : "comment"
|
||||
"url" : "https:\/\/www.example.com\/search?q=12345",
|
||||
"escaped chars" : "\" \\ \/"
|
||||
}
|
||||
|
@ -29,7 +29,9 @@
|
||||
"nested array" : ["lorem", "ipsum"] },
|
||||
"*/" : null,
|
||||
"/**/" : "comment",
|
||||
"//" : "comment"
|
||||
"//" : "comment",
|
||||
"url" : "https:\/\/www.example.com\/search?q=12345",
|
||||
"escaped chars" : "\" \\ \/"
|
||||
}
|
||||
/**/
|
||||
//
|
Loading…
Reference in New Issue
Block a user