Skip to content

Commit 3d5d41f

Browse files
fix undef warning in Mojo::JSON::Pointer when fragment is undef
Use of uninitialized value $pointer in substitution (s///) at .../Mojo/JSON/Pointer.pm line 15.
1 parent a1ffd44 commit 3d5d41f

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Revision history for JSON-Schema-Tiny
22

33
{{$NEXT}}
4+
- fix warning when using a $ref to a URI with no fragment
45

56
0.018 2022-08-06 22:02:20Z
67
- update test skip list for latest release of the test suite

lib/JSON/Schema/Tiny.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ sub _eval_keyword_ref ($data, $schema, $state) {
259259
abort($state, 'only same-document, same-base JSON pointers are supported in %s', $state->{keyword})
260260
if $uri->clone->fragment(undef) ne Mojo::URL->new($state->{root_schema}{'$id'}//'');
261261

262-
my $subschema = Mojo::JSON::Pointer->new($state->{root_schema})->get($uri->fragment);
262+
my $subschema = Mojo::JSON::Pointer->new($state->{root_schema})->get($uri->fragment//'');
263263
abort($state, 'EXCEPTION: unable to find resource %s', $uri) if not defined $subschema;
264264

265265
return _eval_subschema($data, $subschema,

t/ref.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,34 @@ subtest 'local anchor' => sub {
7171
fail;
7272
};
7373

74+
subtest '$ref using the local $id' => sub {
75+
cmp_deeply(
76+
evaluate(
77+
1,
78+
{
79+
'$id' => 'https://localhost:1234/blah',
80+
'$defs' => { 'my-definition' => true },
81+
'$ref' => 'https://localhost:1234/blah#/$defs/my-definition',
82+
},
83+
),
84+
{ valid => true },
85+
'can follow $ref using a base URI that matches our document',
86+
);
87+
88+
cmp_deeply(
89+
evaluate(
90+
[ 'foo', [ 'bar' ] ],
91+
{
92+
'$id' => 'https://localhost:1234/blah',
93+
anyOf => [
94+
{ type => 'string' },
95+
{ type => 'array', items => { '$ref' => 'https://localhost:1234/blah' } },
96+
],
97+
},
98+
),
99+
{ valid => true },
100+
'can follow $ref using a base URI that matches our document',
101+
);
102+
};
103+
74104
done_testing;

0 commit comments

Comments
 (0)