From 0225159a8d0e1260bfec7219b584523097a74d4b Mon Sep 17 00:00:00 2001 From: Alexander Freiherr von Buddenbrock Date: Fri, 4 Nov 2022 13:42:43 +0100 Subject: [PATCH] MDEV-29381: SON paths containing dashes are reported as syntax errors in procedures MDEV-22224 caused the parsing of keys with hyphens to break by setting the state transitions for parsing keys to JE_SYN (syntax error) when they encounter a hyphen. However json key names may contain hyphens and still be considered valid json. This patch changes the state transition table so that key names with hyphens remain valid. Note that unquoted key names in paths like $.key-name are also valid again. This restores the previous behaviour when hyphens were considered part of the P_ETC character class. --- mysql-test/main/func_json.result | 9 +++++++++ mysql-test/main/func_json.test | 7 +++++++ strings/json_lib.c | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index 02f044be479..1d636407ac0 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -2350,3 +2350,12 @@ JSON_OVERLAPS(@json1, @json2) # # End of 10.9 Test # +# +# MDEV-29381: JSON paths containing dashes are reported as syntax errors in procedures +# +SELECT JSON_EXTRACT('{ "my-key": 1 }', '$."my-key"'); +JSON_EXTRACT('{ "my-key": 1 }', '$."my-key"') +1 +SELECT JSON_EXTRACT('{ "my-key": 1 }', '$.my-key'); +JSON_EXTRACT('{ "my-key": 1 }', '$.my-key') +1 diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index 8123ab4be8a..a1613d9ee4f 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -1608,3 +1608,10 @@ SELECT JSON_OVERLAPS(@json1, @json2); --echo # --echo # End of 10.9 Test --echo # + +--echo # +--echo # MDEV-29381: JSON paths containing dashes are reported as syntax errors in procedures +--echo # + +SELECT JSON_EXTRACT('{ "my-key": 1 }', '$."my-key"'); +SELECT JSON_EXTRACT('{ "my-key": 1 }', '$.my-key'); diff --git a/strings/json_lib.c b/strings/json_lib.c index 380959cf204..4cb877baee1 100644 --- a/strings/json_lib.c +++ b/strings/json_lib.c @@ -1096,7 +1096,7 @@ static int json_path_transitions[N_PATH_STATES][N_PATH_CLASSES]= /* KEY */ { JE_EOS, PS_KNM, PS_KWD, JE_SYN, PS_KNM, PS_KNM, JE_SYN, JE_SYN, PS_KNM, PS_KNM, PS_KNM, PS_KNM, PS_KNM, JE_SYN, PS_KEYX, PS_KNM, JE_NOT_JSON_CHR, JE_BAD_CHR}, -/* KNM */ { PS_KOK, PS_KNM, PS_AST, PS_EAR, PS_KNM, PS_KNM, PS_EKY, JE_SYN, +/* KNM */ { PS_KOK, PS_KNM, PS_AST, PS_EAR, PS_KNM, PS_KNM, PS_EKY, PS_KNM, PS_KNM, PS_KNM, PS_KNM, PS_KNM, PS_KNM, PS_ESC, PS_KNM, PS_KNM, JE_NOT_JSON_CHR, JE_BAD_CHR}, /* KWD */ { PS_OK, JE_SYN, JE_SYN, PS_AR, JE_SYN, JE_SYN, PS_EKY, JE_SYN, @@ -1111,7 +1111,7 @@ static int json_path_transitions[N_PATH_STATES][N_PATH_CLASSES]= /* KEYX*/ { JE_EOS, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, JE_SYN, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_ESCX, PS_EKYX, PS_KNMX, JE_NOT_JSON_CHR, JE_BAD_CHR}, -/* KNMX */{ JE_EOS, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, JE_SYN, +/* KNMX */{ JE_EOS, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_KNMX, PS_ESCX, PS_EKYX, PS_KNMX, JE_NOT_JSON_CHR, JE_BAD_CHR}, /* LAST */{ JE_SYN, JE_SYN, JE_SYN, JE_SYN, JE_SYN, PS_PT, JE_SYN, PS_NEG,