Skip to content

Commit 9325453

Browse files
set keyword in state before any errors are generated for that keyword
1 parent 792f79e commit 9325453

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/JSON/Schema/Draft201909.pm

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ sub _eval {
121121
) {
122122
next if not exists $schema->{$keyword};
123123

124+
$state->{keyword} = $keyword;
124125
my $method = '_eval_keyword_'.($keyword =~ s/^\$//r);
125126
abort($state, 'unsupported keyword "%s"', $keyword) if not $self->can($method);
126-
$result = 0 if not $self->$method($data, $schema, +{ %$state, keyword => $keyword });
127+
$result = 0 if not $self->$method($data, $schema, $state);
127128

128129
return 0 if not $result and $state->{short_circuit};
129130
}

t/unsupported-keyword.t

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ foreach my $keyword (qw($id $anchor $recursiveRef $recursiveAnchor $vocabulary))
1414
subtest 'keyword: '.$keyword => sub {
1515
is(
1616
exception {
17-
my $result = $js->evaluate('hello', { $keyword => 'something' });
17+
my $result = $js->evaluate(
18+
'hello',
19+
{
20+
'$schema' => 'https://json-schema.org/draft/2019-09/schema',
21+
$keyword => 'something',
22+
},
23+
);
1824
cmp_deeply(
1925
$result->TO_JSON,
2026
{
2127
valid => bool(0),
2228
errors => [
2329
{
2430
instanceLocation => '',
25-
keywordLocation => '',
31+
keywordLocation => "/$keyword",
2632
error => 'EXCEPTION: unsupported keyword "'.$keyword.'"',
2733
},
2834
],
@@ -31,7 +37,7 @@ foreach my $keyword (qw($id $anchor $recursiveRef $recursiveAnchor $vocabulary))
3137
);
3238
},
3339
undef,
34-
'did not get no exception',
40+
'got an exception',
3541
);
3642
};
3743
}

0 commit comments

Comments
 (0)