Commit b7b8a9ee authored by Rucha Deodhar's avatar Rucha Deodhar

MDEV-23187: Assorted assertion failures in json_find_path with certain

collations

Fix by Alexey Botchkov

The 'value_len' is calculated wrong for the multibyte charsets. In the
read_strn() function we get the length of the string with the final ' " '
character. So have to subtract it's length from the value_len. And the
length of '1' isn't correct for the ucs2 charset (must be 2).
parent 996b040f
...@@ -35,6 +35,7 @@ typedef struct st_json_string_t ...@@ -35,6 +35,7 @@ typedef struct st_json_string_t
const uchar *c_str; /* Current position in JSON string */ const uchar *c_str; /* Current position in JSON string */
const uchar *str_end; /* The end on the string. */ const uchar *str_end; /* The end on the string. */
my_wc_t c_next; /* UNICODE of the last read character */ my_wc_t c_next; /* UNICODE of the last read character */
int c_next_len; /* character lenght of the last read character. */
int error; /* error code. */ int error; /* error code. */
CHARSET_INFO *cs; /* Character set of the JSON string. */ CHARSET_INFO *cs; /* Character set of the JSON string. */
...@@ -48,7 +49,7 @@ void json_string_set_cs(json_string_t *s, CHARSET_INFO *i_cs); ...@@ -48,7 +49,7 @@ void json_string_set_cs(json_string_t *s, CHARSET_INFO *i_cs);
void json_string_set_str(json_string_t *s, void json_string_set_str(json_string_t *s,
const uchar *str, const uchar *end); const uchar *str, const uchar *end);
#define json_next_char(j) \ #define json_next_char(j) \
(j)->wc((j)->cs, &(j)->c_next, (j)->c_str, (j)->str_end) ((j)->c_next_len= (j)->wc((j)->cs, &(j)->c_next, (j)->c_str, (j)->str_end))
#define json_eos(j) ((j)->c_str >= (j)->str_end) #define json_eos(j) ((j)->c_str >= (j)->str_end)
/* /*
read_string_const_chr() reads the next character of the string constant read_string_const_chr() reads the next character of the string constant
......
...@@ -1043,9 +1043,6 @@ SELECT JSON_EXTRACT('{"a":null, "b":10, "c":"null"}', '$.a'); ...@@ -1043,9 +1043,6 @@ SELECT JSON_EXTRACT('{"a":null, "b":10, "c":"null"}', '$.a');
JSON_EXTRACT('{"a":null, "b":10, "c":"null"}', '$.a') JSON_EXTRACT('{"a":null, "b":10, "c":"null"}', '$.a')
null null
# #
# End of 10.3 tests
#
#
# Start of 10.4 tests # Start of 10.4 tests
# #
# #
...@@ -1295,6 +1292,11 @@ SELECT JSON_LENGTH('{"a":"b"}','$','$', 'foo'); ...@@ -1295,6 +1292,11 @@ SELECT JSON_LENGTH('{"a":"b"}','$','$', 'foo');
ERROR 42000: Incorrect parameter count in the call to native function 'json_length' ERROR 42000: Incorrect parameter count in the call to native function 'json_length'
SELECT JSON_LENGTH(); SELECT JSON_LENGTH();
ERROR 42000: Incorrect parameter count in the call to native function 'JSON_LENGTH' ERROR 42000: Incorrect parameter count in the call to native function 'JSON_LENGTH'
# MDEV-23187: Assorted assertion failures in json_find_path with certain collations
SET COLLATION_CONNECTION= ucs2_unicode_ci;
SELECT JSON_VALUE('["foo"]', '$**[0]') AS f;
f
foo
# #
# End of 10.4 tests # End of 10.4 tests
# #
...@@ -665,11 +665,6 @@ SELECT 1 + JSON_VALUE('{"nulltest": null}', '$.nulltest'); ...@@ -665,11 +665,6 @@ SELECT 1 + JSON_VALUE('{"nulltest": null}', '$.nulltest');
SELECT NULL; SELECT NULL;
SELECT JSON_EXTRACT('{"a":null, "b":10, "c":"null"}', '$.a'); SELECT JSON_EXTRACT('{"a":null, "b":10, "c":"null"}', '$.a');
--echo #
--echo # End of 10.3 tests
--echo #
--echo # --echo #
--echo # Start of 10.4 tests --echo # Start of 10.4 tests
--echo # --echo #
...@@ -825,6 +820,12 @@ SELECT JSON_LENGTH('{"a":"b"}','$','$', 'foo'); ...@@ -825,6 +820,12 @@ SELECT JSON_LENGTH('{"a":"b"}','$','$', 'foo');
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT --error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
SELECT JSON_LENGTH(); SELECT JSON_LENGTH();
--echo # MDEV-23187: Assorted assertion failures in json_find_path with certain collations
SET COLLATION_CONNECTION= ucs2_unicode_ci;
SELECT JSON_VALUE('["foo"]', '$**[0]') AS f;
--echo # --echo #
--echo # End of 10.4 tests --echo # End of 10.4 tests
--echo # --echo #
...@@ -401,7 +401,7 @@ static int read_strn(json_engine_t *j) ...@@ -401,7 +401,7 @@ static int read_strn(json_engine_t *j)
return 1; return 1;
j->state= j->stack[j->stack_p]; j->state= j->stack[j->stack_p];
j->value_len= (int)(j->s.c_str - j->value) - 1; j->value_len= (int)(j->s.c_str - j->value) - j->s.c_next_len;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment