Skip to content

Commit

Permalink
MDEV-22141: JSON_REMOVE returns NULL on valid arguments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mariadb-RuchaDeodhar committed Apr 29, 2024
1 parent 5ca64e6 commit 9e6858a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mysql-test/main/func_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -1711,5 +1711,11 @@ NULL
Warnings:
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_type' at position 5
#
# MDEV-22141: JSON_REMOVE returns NULL on valid arguments
#
SELECT JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D');
JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D')
{"A": {"B": 1}}
#
# End of 10.5 tests
#
7 changes: 7 additions & 0 deletions mysql-test/main/func_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,13 @@ DROP TABLE t;
SELECT JSON_TYPE(json_value(JSON_OBJECT("id", 1, "name", 'Monty', "date", Cast('2019-01-01' as Date) ), '$.date'));


--echo #
--echo # MDEV-22141: JSON_REMOVE returns NULL on valid arguments
--echo #

SELECT JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D');


--echo #
--echo # End of 10.5 tests
--echo #
1 change: 1 addition & 0 deletions sql/item_jsonfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3332,6 +3332,7 @@ String *Item_func_json_remove::val_str(String *str)
{
if (je.s.error)
goto js_error;
continue;
}

if (json_read_value(&je))
Expand Down

0 comments on commit 9e6858a

Please sign in to comment.