diff --git a/expression/integration_test.go b/expression/integration_test.go index 379b08e35ffca..be9448a1e0048 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7532,6 +7532,42 @@ func TestCastRealAsTime(t *testing.T) { " ")) } +func TestJSONDepth(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t(a JSON)") + tk.MustGetErrCode(`insert into t +with recursive c1 as (select cast(1 as signed) c, json_array(1) as a + union + select c + 1, json_array_insert(a, concat('$', repeat('[0]', c)), json_array(1)) + from c1 + where c < 101) +select a from c1 where c > 100;`, errno.ErrJSONDocumentTooDeep) + tk.MustExec(`insert into t +with recursive c1 as (select cast(1 as signed) c, json_array(1) as a + union + select c + 1, json_array_insert(a, concat('$', repeat('[0]', c)), json_array(1)) + from c1 + where c < 100) +select a from c1 where c > 99;`) + + err := tk.QueryToErr(`select json_array(a, 1) from t`) + require.Error(t, err) + // FIXME: mysql client shows the error. + //err = tk.QueryToErr(`select json_objectagg(1, a) from t;`) + //require.Error(t, err) + err = tk.QueryToErr(`select json_object(1, a) from t;`) + require.Error(t, err) + err = tk.QueryToErr(`select json_set(a, concat('$', repeat('[0]', 100)), json_array(json_array(3))) from t;`) + require.Error(t, err) + err = tk.QueryToErr(`select json_array_append(a, concat('$', repeat('[0]', 100)), 1) from t;`) + require.Error(t, err) + // FIXME: mysql client shows the error. + //err = tk.QueryToErr(`select json_arrayagg(a) from t;`) + //require.Error(t, err) +} + func TestCastJSONTimeDuration(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store)