diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2022-03-01 16:14:36 +0530 |
---|---|---|
committer | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2022-04-13 21:16:32 +0530 |
commit | abe971219456b1f41923c06ff715fd4efeb02850 (patch) | |
tree | 1661de489d87f8c6bbde19c4188bfe3906f02a62 | |
parent | dfcbb30a92c2f1d33ceefb56a1d3fa13f8d0ce67 (diff) | |
download | mariadb-git-abe971219456b1f41923c06ff715fd4efeb02850.tar.gz |
MDEV-27972: Unexpected behavior with negative zero (-0) in
JSON Path
Analysis: When we have '-' followed by 0, then the state is
changed to JE_SYN, meaning syntax error.
Fix: Change the state to PS_INT instead, because we are
reading '0' next (integer) and it is not a syntax error.
-rw-r--r-- | mysql-test/main/func_json.result | 16 | ||||
-rw-r--r-- | mysql-test/main/func_json.test | 10 | ||||
-rw-r--r-- | strings/json_lib.c | 2 |
3 files changed, 27 insertions, 1 deletions
diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index 5bcd90f3410..18a700607ab 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -2013,5 +2013,21 @@ SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); JSON_VALUE(@json, '$.A[last-1][last-1].key1') 123 # +# MDEV-27972: Unexpected behavior with negative zero (-0) in JSON Path +# +SET @json='{ "x": [0,1]}'; +SELECT JSON_VALUE(@json,'$.x[last]'); +JSON_VALUE(@json,'$.x[last]') +1 +SELECT JSON_VALUE(@json,'$.x[last-0]'); +JSON_VALUE(@json,'$.x[last-0]') +1 +SELECT JSON_VALUE(@json,'$.x[-0]'); +JSON_VALUE(@json,'$.x[-0]') +0 +SELECT JSON_VALUE(@json,'$.x[0]'); +JSON_VALUE(@json,'$.x[0]') +0 +# # End of 10.9 Test # diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index ea7358f4563..34a4b30b0ab 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -1307,5 +1307,15 @@ SELECT JSON_VALUE(@json, '$.A[-2][-2].key1'); SELECT JSON_VALUE(@json, '$.A[last-1][last-1].key1'); --echo # +--echo # MDEV-27972: Unexpected behavior with negative zero (-0) in JSON Path +--echo # + +SET @json='{ "x": [0,1]}'; +SELECT JSON_VALUE(@json,'$.x[last]'); +SELECT JSON_VALUE(@json,'$.x[last-0]'); +SELECT JSON_VALUE(@json,'$.x[-0]'); +SELECT JSON_VALUE(@json,'$.x[0]'); + +--echo # --echo # End of 10.9 Test --echo # diff --git a/strings/json_lib.c b/strings/json_lib.c index 526a55b7179..602a57cc03b 100644 --- a/strings/json_lib.c +++ b/strings/json_lib.c @@ -1079,7 +1079,7 @@ static int json_path_transitions[N_PATH_STATES][N_PATH_CLASSES]= /* AWD */ { JE_EOS, JE_SYN, JE_SYN, JE_SYN, PS_PT, JE_SYN,JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_SYN, PS_AS, JE_SYN, JE_SYN, JE_SYN, JE_NOT_JSON_CHR, JE_BAD_CHR}, -/* NEG */ { JE_EOS, JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_SYN,JE_SYN, +/* NEG */ { JE_EOS, JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_SYN, PS_INT, PS_INT, JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_NOT_JSON_CHR, JE_BAD_CHR}, /* Z */ { JE_EOS, JE_SYN, JE_SYN, JE_SYN, PS_PT, JE_SYN,JE_SYN, JE_SYN, |