diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2017-03-14 15:25:02 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2017-03-14 15:25:02 +0400 |
commit | 7c7c0696e7eba3717a592c7c2c28c46af26e3e68 (patch) | |
tree | e4a34aec3eab1c63a4ffbf32c1cee96e49e6cde8 /sql/item_jsonfunc.cc | |
parent | a77c2ea78f76c07446a3014052cb8c3b74c4860c (diff) | |
download | mariadb-git-7c7c0696e7eba3717a592c7c2c28c46af26e3e68.tar.gz |
MDEV-11856 json_search doesn't search for values with double quotes
character (").
The my_wildcmp function doesn't expect the string parameter to
have escapements, only the template. So the string
should be unescaped if necessary.
Diffstat (limited to 'sql/item_jsonfunc.cc')
-rw-r--r-- | sql/item_jsonfunc.cc | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 925a7e437f2..7909c605136 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -2800,9 +2800,28 @@ void Item_func_json_search::fix_length_and_dec() int Item_func_json_search::compare_json_value_wild(json_engine_t *je, const String *cmp_str) { - return my_wildcmp(collation.collation, - (const char *) je->value, (const char *) (je->value + je->value_len), - cmp_str->ptr(), cmp_str->end(), escape, wild_one, wild_many) ? 0 : 1; + if (je->value_type != JSON_VALUE_STRING || !je->value_escaped) + return my_wildcmp(collation.collation, + (const char *) je->value, (const char *) (je->value + je->value_len), + cmp_str->ptr(), cmp_str->end(), escape, wild_one, wild_many) ? 0 : 1; + + { + int esc_len; + if (esc_value.alloced_length() < (uint) je->value_len && + esc_value.alloc((je->value_len / 1024 + 1) * 1024)) + return 0; + + esc_len= json_unescape(je->s.cs, je->value, je->value + je->value_len, + je->s.cs, (uchar *) esc_value.ptr(), + (uchar *) (esc_value.ptr() + + esc_value.alloced_length())); + if (esc_len <= 0) + return 0; + + return my_wildcmp(collation.collation, + esc_value.ptr(), esc_value.ptr() + esc_len, + cmp_str->ptr(), cmp_str->end(), escape, wild_one, wild_many) ? 0 : 1; + } } |