Skip to content

Commit 9e6858a

Browse files
MDEV-22141: JSON_REMOVE returns NULL on valid arguments
Analysis: When we scan json to get to a beginning according to the path, we end up scanning json even if we have exhausted it. When eventually returns error. Fix: Continue scanning json only if we have not exhausted it and return result accordingly.
1 parent 5ca64e6 commit 9e6858a

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

mysql-test/main/func_json.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,5 +1711,11 @@ NULL
17111711
Warnings:
17121712
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 5
17131713
#
1714+
# MDEV-22141: JSON_REMOVE returns NULL on valid arguments
1715+
#
1716+
SELECT JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D');
1717+
JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D')
1718+
{"A": {"B": 1}}
1719+
#
17141720
# End of 10.5 tests
17151721
#

mysql-test/main/func_json.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,13 @@ DROP TABLE t;
11401140
SELECT JSON_TYPE(json_value(JSON_OBJECT("id", 1, "name", 'Monty', "date", Cast('2019-01-01' as Date) ), '$.date'));
11411141

11421142

1143+
--echo #
1144+
--echo # MDEV-22141: JSON_REMOVE returns NULL on valid arguments
1145+
--echo #
1146+
1147+
SELECT JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D');
1148+
1149+
11431150
--echo #
11441151
--echo # End of 10.5 tests
11451152
--echo #

sql/item_jsonfunc.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,6 +3332,7 @@ String *Item_func_json_remove::val_str(String *str)
33323332
{
33333333
if (je.s.error)
33343334
goto js_error;
3335+
continue;
33353336
}
33363337

33373338
if (json_read_value(&je))

0 commit comments

Comments
 (0)