mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
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.
This commit is contained in:
parent
a77c2ea78f
commit
7c7c0696e7
6 changed files with 39 additions and 4 deletions
|
@ -203,6 +203,7 @@ typedef struct st_json_engine_t
|
|||
enum json_value_types value_type; /* type of the value.*/
|
||||
const uchar *value; /* Points to the value. */
|
||||
const uchar *value_begin;/* Points to where the value starts in the JSON. */
|
||||
int value_escaped; /* Flag telling if the string value has escaping.*/
|
||||
uint num_flags; /* the details of the JSON_VALUE_NUMBER, is it negative,
|
||||
or if it has the fractional part.
|
||||
See the enum json_num_flags. */
|
||||
|
|
|
@ -589,3 +589,9 @@ json_detailed('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}')
|
|||
"bb": "v2"
|
||||
}
|
||||
}
|
||||
SELECT JSON_search( '{"x": "\\""}', "one", '"');
|
||||
JSON_search( '{"x": "\\""}', "one", '"')
|
||||
"$.x"
|
||||
SELECT JSON_search( '{"x": "\\""}', "one", '\\"');
|
||||
JSON_search( '{"x": "\\""}', "one", '\\"')
|
||||
"$.x"
|
||||
|
|
|
@ -238,3 +238,10 @@ select json_merge('{"a":{"u":12, "x":"b", "r":1}}', '{"a":{"x":"c", "r":2}}') ;
|
|||
select json_compact('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}');
|
||||
select json_loose('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}');
|
||||
select json_detailed('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}');
|
||||
|
||||
#
|
||||
# MDEV-11856 json_search doesn't search for values with double quotes character (")
|
||||
#
|
||||
|
||||
SELECT JSON_search( '{"x": "\\""}', "one", '"');
|
||||
SELECT JSON_search( '{"x": "\\""}', "one", '\\"');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -392,7 +392,7 @@ public:
|
|||
class Item_func_json_search: public Item_json_str_multipath
|
||||
{
|
||||
protected:
|
||||
String tmp_js;
|
||||
String tmp_js, esc_value;
|
||||
bool mode_one;
|
||||
bool ooa_constant, ooa_parsed;
|
||||
int escape;
|
||||
|
|
|
@ -366,6 +366,7 @@ static int skip_str_constant(json_engine_t *j)
|
|||
break;
|
||||
if (j->s.c_next == '\\')
|
||||
{
|
||||
j->value_escaped= 1;
|
||||
if (json_handle_esc(&j->s))
|
||||
return 1;
|
||||
continue;
|
||||
|
@ -394,6 +395,7 @@ static int read_strn(json_engine_t *j)
|
|||
{
|
||||
j->value= j->s.c_str;
|
||||
j->value_type= JSON_VALUE_STRING;
|
||||
j->value_escaped= 0;
|
||||
|
||||
if (skip_str_constant(j))
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue