diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index fe5c390d88f..d0ed75e726c 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -91,6 +91,9 @@ json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.key2") select json_contains_path('{ "a": true }', NULL, '$.a' ); json_contains_path('{ "a": true }', NULL, '$.a' ) NULL +select json_contains_path('{ "a": true }', 'all', NULL ); +json_contains_path('{ "a": true }', 'all', NULL ) +NULL select json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1"); json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1") "asd" diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index 85f9d2e2270..0245cf382ee 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -36,6 +36,7 @@ select json_contains_path('{"key1":1, "key2":[2,3]}', "one", "$.key1", "$.ma"); select json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.ma"); select json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.key2"); select json_contains_path('{ "a": true }', NULL, '$.a' ); +select json_contains_path('{ "a": true }', 'all', NULL ); select json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1"); select json_extract('{"key1":"asd", "key2":[2,3]}', "$.keyX", "$.keyY"); diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 42ad5470965..c22881620ff 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -450,6 +450,9 @@ String *Item_func_json_extract::val_str(String *str) c_path->parsed= c_path->constant; } + if (args[n_arg]->null_value) + goto error; + json_scan_start(&je, js->charset(),(const uchar *) js->ptr(), (const uchar *) js->ptr() + js->length()); @@ -547,6 +550,9 @@ longlong Item_func_json_extract::val_int() c_path->parsed= c_path->constant; } + if (args[n_arg]->null_value) + goto error; + json_scan_start(&je, js->charset(),(const uchar *) js->ptr(), (const uchar *) js->ptr() + js->length()); @@ -661,6 +667,9 @@ longlong Item_func_json_contains::val_int() c_path->parsed= c_path->constant; } + if (args[n_arg]->null_value) + goto error; + json_scan_start(&je, js->charset(),(const uchar *) js->ptr(), (const uchar *) js->ptr() + js->length()); @@ -768,6 +777,9 @@ longlong Item_func_json_contains_path::val_int() c_path->parsed= c_path->constant; } + if (args[n_arg]->null_value) + goto error; + json_scan_start(&je, js->charset(),(const uchar *) js->ptr(), (const uchar *) js->ptr() + js->length()); @@ -1946,6 +1958,9 @@ String *Item_func_json_search::val_str(String *str) } } + if (args[n_arg]->null_value) + goto null_return; + json_scan_start(&je, js->charset(),(const uchar *) js->ptr(), (const uchar *) js->ptr() + js->length());