Skip to content

Commit d935a26

Browse files
detect autovivification everywhere
At runtime this just warns, but during author tests we fail on warnings.
1 parent 500ff54 commit d935a26

20 files changed

+29
-6
lines changed

lib/JSON/Schema/Tiny.pm

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ our $VERSION = '0.025';
1010
use 5.020; # for unicode_strings, signatures, postderef features
1111
use stable 0.031 'postderef';
1212
use experimental 0.026 qw(signatures args_array_with_signatures);
13+
no autovivification warn => qw(fetch store exists delete);
1314
use if "$]" >= 5.022, experimental => 're_strict';
1415
no if "$]" >= 5.031009, feature => 'indirect';
1516
no if "$]" >= 5.033001, feature => 'multidimensional';
@@ -146,10 +147,13 @@ sub _eval_subschema ($data, $schema, $state) {
146147
# if any of them are absolute prefix of this schema location, we are in a loop.
147148
my $canonical_uri = canonical_uri($state);
148149
my $schema_location = $state->{traversed_schema_path}.$state->{schema_path};
149-
abort($state, 'EXCEPTION: infinite loop detected (same location evaluated twice)')
150-
if grep substr($schema_location, 0, length) eq $_,
151-
keys $state->{seen}{$state->{data_path}}{$canonical_uri}->%*;
152-
$state->{seen}{$state->{data_path}}{$canonical_uri}{$schema_location}++;
150+
{
151+
use autovivification qw(fetch store);
152+
abort($state, 'EXCEPTION: infinite loop detected (same location evaluated twice)')
153+
if grep substr($schema_location, 0, length) eq $_,
154+
keys $state->{seen}{$state->{data_path}}{$canonical_uri}->%*;
155+
$state->{seen}{$state->{data_path}}{$canonical_uri}{$schema_location}++;
156+
}
153157

154158
my $schema_type = get_type($schema);
155159
return $schema || E($state, 'subschema is false') if $schema_type eq 'boolean';
@@ -211,7 +215,7 @@ sub _eval_subschema ($data, $schema, $state) {
211215
}
212216

213217
# check for previously-supported but now removed keywords
214-
foreach my $keyword (sort keys $removed_keywords{$spec_version}->%*) {
218+
foreach my $keyword (sort keys(($removed_keywords{$spec_version}//{})->%*)) {
215219
next if not exists $schema->{$keyword};
216220
my $message ='no-longer-supported "'.$keyword.'" keyword present (at location "'
217221
.canonical_uri($state).'")';

t/additional-tests-draft2019-09.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/additional-tests-draft2020-12.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/additional-tests-draft7.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/boolean-data.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/boolean-schemas.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/equality.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/errors.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/lib/Acceptance.pm

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use strictures 2;
55
use 5.020;
66
use stable 0.031 'postderef';
77
use experimental 'signatures';
8+
no autovivification warn => qw(fetch store exists delete);
89
use if "$]" >= 5.022, experimental => 're_strict';
910
no if "$]" >= 5.031009, feature => 'indirect';
1011
no if "$]" >= 5.033001, feature => 'multidimensional';
@@ -67,7 +68,7 @@ sub acceptance_tests (%options) {
6768
&& $_->{error} !~ /but short_circuit is enabled/ # unevaluated*
6869
&& $_->{error} !~ /(max|min)imum value is not a number$/) # optional/bignum.json
6970
&& !($in_todo //= grep $_->{todo}, Test2::API::test2_stack->top->{_pre_filters}->@*),
70-
$r->{errors}->@*;
71+
($r->{errors}//[])->@*;
7172
}
7273

7374
$result->{valid};

t/lib/Helper.pm

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use strictures 2;
55
use 5.020;
66
use stable 0.031 'postderef';
77
use experimental 'signatures';
8+
no autovivification warn => qw(fetch store exists delete);
89
use if "$]" >= 5.022, experimental => 're_strict';
910
no if "$]" >= 5.031009, feature => 'indirect';
1011
no if "$]" >= 5.033001, feature => 'multidimensional';

t/max_traversal_depth.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/pattern.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/ref.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/specification_version.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/stringy-numbers.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/type.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/unsupported-keywords.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/zzz-acceptance-draft2019-09.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/zzz-acceptance-draft2020-12.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

t/zzz-acceptance-draft7.t

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use strictures 2;
33
use 5.020;
44
use stable 0.031 'postderef';
55
use experimental 'signatures';
6+
no autovivification warn => qw(fetch store exists delete);
67
use if "$]" >= 5.022, experimental => 're_strict';
78
no if "$]" >= 5.031009, feature => 'indirect';
89
no if "$]" >= 5.033001, feature => 'multidimensional';

0 commit comments

Comments
 (0)