-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 |
|---|---|---|
|
|
@@ -233,12 +233,18 @@ void dump_mrr_info_calls(List<Multi_range_read_const_call_record> *mrr_list, | |
| Json_writer_object irc_wrapper(ctx_writer); | ||
| irc_wrapper.add("index_name", irc->idx_name); | ||
|
|
||
| List_iterator rc_li(irc->range_list); | ||
| Json_writer_array ranges_wrapper(ctx_writer, "ranges"); | ||
| StringBuffer<128> escaped_range_info; | ||
| while (const char *range_str= rc_li++) | ||
| { | ||
| Json_writer_array ranges_wrapper(ctx_writer, "ranges"); | ||
| List_iterator rc_li(irc->range_list); | ||
| while (const char *range_str= rc_li++) | ||
| ranges_wrapper.add(range_str, strlen(range_str)); | ||
| const String range_info(range_str, strlen(range_str), | ||
| system_charset_info); | ||
| json_escape_to_string(&range_info, &escaped_range_info); | ||
| ranges_wrapper.add(escaped_range_info.c_ptr_safe(), | ||
| escaped_range_info.length()); | ||
| } | ||
| ranges_wrapper.end(); | ||
|
|
||
| irc_wrapper.add("num_rows", irc->rows); | ||
| { | ||
|
|
@@ -518,6 +524,31 @@ static bool store_db_ddl(THD *thd, HASH *db_name_hash, String &script, | |
| return false; | ||
| } | ||
|
|
||
| /* | ||
| @brief | ||
| Append the json "str" to sql_script, by escaping only backslash, | ||
| and single quote | ||
| */ | ||
| static void escape_json_for_sql_literal(String &sql_script, const char *str, | ||
| size_t len) | ||
| { | ||
| const char *end= str + len; | ||
| for (; str < end; str++) | ||
| { | ||
| switch (*str) | ||
| { | ||
| case '\\': | ||
| sql_script.append(STRING_WITH_LEN("\\\\")); | ||
| break; | ||
| case '\'': | ||
| sql_script.append(STRING_WITH_LEN("\\'")); | ||
| break; | ||
| default: | ||
| sql_script.append(*str); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| @brief | ||
| Dump definitions, basic stats of all tables and views used by the | ||
|
|
@@ -719,9 +750,12 @@ bool store_optimizer_context(THD *thd) | |
| const char *SET_OPT_CONTEXT_VAR= "set @opt_context=\'\n"; | ||
| const char *SET_REPLAY_CONTEXT_VAR= | ||
| "set optimizer_replay_context=\'opt_context\'"; | ||
| String *s= const_cast<String *>(ctx_writer.output.get_string()); | ||
| sql_script.append(SET_OPT_CONTEXT_VAR, strlen(SET_OPT_CONTEXT_VAR)); | ||
| sql_script.append(*s); | ||
| String *opt_context= const_cast<String *>(ctx_writer.output.get_string()); | ||
| // require extra escaping of the opt_ctx so as to counter the | ||
| // unescaping done by sql parse | ||
| escape_json_for_sql_literal(sql_script, opt_context->c_ptr_safe(), | ||
| opt_context->length()); | ||
|
Member
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. The above could just be const String *opt_context= ctx_writer.output.get_string();
// require extra escaping of the opt_ctx so as to counter the
// unescaping done by sql parse
escape_json_for_sql_literal(sql_script, opt_context->ptr(),
opt_context->length());but please wait for other input before fixing |
||
| sql_script.append(STRING_WITH_LEN("\n\';#opt_context_ends\n\n")); | ||
| sql_script.append(SET_REPLAY_CONTEXT_VAR, strlen(SET_REPLAY_CONTEXT_VAR)); | ||
| sql_script.append(STRING_WITH_LEN(";\n\n")); | ||
|
|
||
| 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
Member
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. Confirm. We should address Gemini's input here.
Contributor
Author
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. addressed it. |
||
| ok(!rc, "Basic object read"); | ||
| free_root(&alloc, 0); | ||
| #if 0 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.