Commit 9cc179cc authored by Rucha Deodhar's avatar Rucha Deodhar

MDEV-32007: JSON_VALUE and JSON_EXTRACT doesn't handle dash (-)

as first character in key

Analysis:
While parsing the path, if '-' is encountered as a part of the key,
the state of the parser changes to error. Hence NULL is returned eventually.

Fix:
If '-' encountered as part of the key, change the state appropriately to
continue scanning the key.
parent be24e752
...@@ -2608,3 +2608,24 @@ SET @@collation_connection= @save_collation_connection; ...@@ -2608,3 +2608,24 @@ SET @@collation_connection= @save_collation_connection;
# #
# End of 10.9 Test # End of 10.9 Test
# #
#
# MDEV-32007: JSON_VALUE and JSON_EXTRACT doesn't handle dash (-)
# as first character in key
#
CREATE TEMPORARY TABLE IF NOT EXISTS jsonTest AS
SELECT '{ "-1234" : "something",
"12-34" : "else",
"1234-" : "and",
"1234" : "match" }' AS 'message';
SELECT JSON_SEARCH(message, 'one', 'something') AS t1_path,
JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'something'))) AS t1_result,
JSON_SEARCH(message, 'one', 'else') AS t2_path,
JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'else'))) AS t2_result,
JSON_SEARCH(message, 'one', 'and') AS t3_path,
JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'and'))) AS t3_result,
JSON_SEARCH(message, 'one', 'match') AS t4_path,
JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'match'))) AS t4_result
FROM jsonTest;
t1_path t1_result t2_path t2_result t3_path t3_result t4_path t4_result
"$.-1234" something "$.12-34" else "$.1234-" and "$.1234" match
# End of 11.0 test
...@@ -1809,3 +1809,26 @@ SET @@collation_connection= @save_collation_connection; ...@@ -1809,3 +1809,26 @@ SET @@collation_connection= @save_collation_connection;
--echo # --echo #
--echo # End of 10.9 Test --echo # End of 10.9 Test
--echo # --echo #
--echo #
--echo # MDEV-32007: JSON_VALUE and JSON_EXTRACT doesn't handle dash (-)
--echo # as first character in key
--echo #
CREATE TEMPORARY TABLE IF NOT EXISTS jsonTest AS
SELECT '{ "-1234" : "something",
"12-34" : "else",
"1234-" : "and",
"1234" : "match" }' AS 'message';
SELECT JSON_SEARCH(message, 'one', 'something') AS t1_path,
JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'something'))) AS t1_result,
JSON_SEARCH(message, 'one', 'else') AS t2_path,
JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'else'))) AS t2_result,
JSON_SEARCH(message, 'one', 'and') AS t3_path,
JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'and'))) AS t3_result,
JSON_SEARCH(message, 'one', 'match') AS t4_path,
JSON_VALUE(message, JSON_UNQUOTE(JSON_SEARCH(message, 'one', 'match'))) AS t4_result
FROM jsonTest;
--echo # End of 11.0 test
...@@ -1093,7 +1093,7 @@ static int json_path_transitions[N_PATH_STATES][N_PATH_CLASSES]= ...@@ -1093,7 +1093,7 @@ static int json_path_transitions[N_PATH_STATES][N_PATH_CLASSES]=
/* AS */ { JE_EOS, JE_SYN, JE_SYN, JE_SYN, PS_T, PS_PT, JE_SYN, PS_NEG, /* AS */ { JE_EOS, JE_SYN, JE_SYN, JE_SYN, PS_T, PS_PT, JE_SYN, PS_NEG,
PS_Z, PS_INT, PS_LAST, PS_AS, JE_SYN, JE_SYN, JE_SYN, PS_Z, PS_INT, PS_LAST, PS_AS, JE_SYN, JE_SYN, JE_SYN,
JE_NOT_JSON_CHR, JE_BAD_CHR}, JE_NOT_JSON_CHR, JE_BAD_CHR},
/* KEY */ { JE_EOS, PS_KNM, PS_KWD, JE_SYN, PS_KNM, PS_KNM, JE_SYN, JE_SYN, /* KEY */ { JE_EOS, PS_KNM, PS_KWD, JE_SYN, PS_KNM, PS_KNM, JE_SYN, PS_KNM,
PS_KNM, PS_KNM, PS_KNM, PS_KNM, PS_KNM, JE_SYN, PS_KEYX, PS_KNM, PS_KNM, PS_KNM, PS_KNM, PS_KNM, PS_KNM, JE_SYN, PS_KEYX, PS_KNM,
JE_NOT_JSON_CHR, JE_BAD_CHR}, JE_NOT_JSON_CHR, JE_BAD_CHR},
/* KNM */ { PS_KOK, PS_KNM, PS_AST, PS_EAR, PS_KNM, PS_KNM, PS_EKY, PS_KNM, /* KNM */ { PS_KOK, PS_KNM, PS_AST, PS_EAR, PS_KNM, PS_KNM, PS_EKY, PS_KNM,
......
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