-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-39412: parse error reading tabs in ranges #5049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bb-12.3-MDEV-39368-test-replay
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,17 +78,7 @@ bool read_string(MEM_ROOT *mem_root, json_engine_t *je, const char *read_elem_ke | |
| if (check_reading_of_elem_key(je, read_elem_key, err_buf)) | ||
| return true; | ||
|
|
||
| StringBuffer<128> val_buf; | ||
| if (json_unescape_to_string((const char *) je->value, je->value_len, | ||
| &val_buf)) | ||
| { | ||
| err_buf->append(STRING_WITH_LEN("un-escaping error of ")); | ||
| err_buf->append(read_elem_key, strlen(read_elem_key)); | ||
| err_buf->append(STRING_WITH_LEN(" element")); | ||
| return true; | ||
| } | ||
|
|
||
| value= strdup_root(mem_root, val_buf.c_ptr_safe()); | ||
| value= strmake_root(mem_root, (const char *) je->value, je->value_len); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the unescaping logic from The issue described in the PR (where By removing unescaping here, you are making the JSON reader return the raw, escaped content of the JSON string, which is non-standard and will break other potential users of this utility function. Please restore the unescaping logic. StringBuffer<128> val_buf;
if (json_unescape_to_string((const char *) je->value, je->value_len,
&val_buf))
{
err_buf->append(STRING_WITH_LEN("un-escaping error of "));
err_buf->append(read_elem_key, strlen(read_elem_key));
err_buf->append(STRING_WITH_LEN(" element"));
return true;
}
value= strdup_root(mem_root, val_buf.c_ptr_safe()); |
||
| return false; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,25 +39,29 @@ int main(int args, char **argv) | |
| MEM_ROOT alloc; | ||
| json_engine_t je; | ||
| int rc; | ||
| const char *esc_str_val= "a\\bc"; | ||
| init_alloc_root(0, &alloc, 32768, 0, 0); | ||
| mem_root_dynamic_array_init(&alloc, 0, &je.stack, | ||
| sizeof(int), NULL, JSON_DEPTH_DEFAULT, | ||
| JSON_DEPTH_INC, MYF(0)); | ||
| system_charset_info= &my_charset_utf8mb3_bin; | ||
| const char *js_doc="{ \"str_val\": \"abc\", \"double_val\": 1234.5 }"; | ||
| const char *js_doc= "{ \"str_val\": \"abc\", \"double_val\": 1234.5, " | ||
| "\"esc_str_val\": \"a\\bc\" }"; | ||
| json_scan_start(&je, &my_charset_utf8mb3_bin, (const uchar *) js_doc, | ||
| (const uchar *) js_doc + strlen(js_doc)); | ||
|
|
||
| char *parsed_name; | ||
| double parsed_dbl; | ||
| char *parsed_esc_str; | ||
| Read_named_member array[]= { | ||
| {"str_val", Read_string(&alloc, &parsed_name), false}, | ||
| {"str_val", Read_string(&alloc, &parsed_name), false}, | ||
| {"double_val", Read_double(&parsed_dbl), false}, | ||
| {NULL, Read_double(NULL), false } | ||
| }; | ||
| {"esc_str_val", Read_string(&alloc, &parsed_esc_str), false}, | ||
| {NULL, Read_double(NULL), false}}; | ||
| String err_buf; | ||
|
|
||
| rc= json_read_object(&je, array, &err_buf); | ||
| rc= json_read_object(&je, array, &err_buf) || | ||
| strcmp(parsed_esc_str, esc_str_val); | ||
|
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test change validates that the reader does NOT unescape, which is incorrect for a JSON library. For example, a JSON string |
||
| ok(!rc, "Basic object read"); | ||
| free_root(&alloc, 0); | ||
| #if 0 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation re-allocates the
StringBufferand its internal storage on every iteration of the loop. It is more efficient to move the buffer declaration outside the loop and reuse it by clearing its length in each iteration. Additionally, using a scoped block for theJson_writer_arrayis a cleaner way to ensure the array is closed correctly via its destructor, rather than callingend()explicitly.{ Json_writer_array ranges_wrapper(ctx_writer, "ranges"); List_iterator rc_li(irc->range_list); StringBuffer<128> escaped_range_info; while (const char *range_str= rc_li++) { const String range_info(range_str, strlen(range_str), system_charset_info); escaped_range_info.length(0); json_escape_to_string(&range_info, &escaped_range_info); ranges_wrapper.add(escaped_range_info.c_ptr_safe(), escaped_range_info.length()); } }