Skip to content

Commit 2b01461

Browse files
author
Alexey Botchkov
committed
MDEV-11465 JSON_LENGTH returns incorrect length.
Item_func_json_length::val_int fixed.
1 parent 75a5181 commit 2b01461

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

mysql-test/r/func_json.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,12 @@ json_depth('[[], {}]')
292292
select json_depth('[[[1,2,3],"s"], {}, []]');
293293
json_depth('[[[1,2,3],"s"], {}, []]')
294294
4
295+
select json_length('');
296+
json_length('')
297+
NULL
298+
select json_length('{}');
299+
json_length('{}')
300+
0
301+
select json_length('[1, 2, {"a": 3}]');
302+
json_length('[1, 2, {"a": 3}]')
303+
3

mysql-test/t/func_json.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@ select json_depth(cast(NULL as JSON));
129129
select json_depth('[[], {}]');
130130
select json_depth('[[[1,2,3],"s"], {}, []]');
131131

132+
select json_length('');
133+
select json_length('{}');
134+
select json_length('[1, 2, {"a": 3}]');

sql/item_jsonfunc.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,8 +1271,7 @@ longlong Item_func_json_length::val_int()
12711271
return 0;
12721272
}
12731273

1274-
return length;
1275-
1274+
return length - 1;
12761275
}
12771276

12781277

0 commit comments

Comments
 (0)