jsonfmt: Add max_size and max_depth options

This commit is contained in:
Yorhel 2025-01-29 15:05:48 +01:00
parent a85ff98914
commit 163a60b4ba
4 changed files with 101 additions and 59 deletions

View file

@ -68,7 +68,7 @@ my @errors = (
do { my $o = {}; bless $o, 'MyToJSONSelf' }, qr/MyToJSONSelf::TO_JSON method returned same object as was passed instead of a new one/,
);
plan tests => @tests*2 + @errors/2 + 6;
plan tests => @tests*2 + @errors/2 + 8;
for my($in, $exp) (@tests) {
my $out = json_format $in;
@ -87,6 +87,12 @@ for my ($in, $exp) (@errors) {
}
eval { json_format [[]], max_depth => 2 };
like $@, qr/max_depth exceeded while formatting JSON/;
eval { json_format 'hello world', max_size => 8 };
like $@, qr/maximum string length exceeded/;
# http://e-choroba.eu/18-yapc slide 6