Skip to content

Commit

Permalink
fix bug in Mojo::JSON::Pointer that prevented JSON Pointers with trai…
Browse files Browse the repository at this point in the history
…ling slash from working correctly (closes #851)
  • Loading branch information
kraih committed Oct 13, 2015
1 parent 9b4d8ce commit 9d05a4c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -3,6 +3,8 @@
- Improved session security by not storing secrets in the stash and making
CSRF tokens much harder to guess.
- Improved commands to show all options that can affect their behavior.
- Fixed bug in Mojo::JSON::Pointer that prevented JSON Pointers with traling
slash from working correctly. (dolmen)

6.23 2015-10-06
- Improved documentation browser CSS.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/JSON/Pointer.pm
Expand Up @@ -13,7 +13,7 @@ sub _pointer {

my $data = $self->data;
return $data unless $pointer =~ s!^/!!;
for my $p ($pointer eq '' ? ($pointer) : (split '/', $pointer)) {
for my $p ($pointer eq '' ? ($pointer) : (split '/', $pointer, -1)) {
$p =~ s!~1!/!g;
$p =~ s/~0/~/g;

Expand Down
2 changes: 2 additions & 0 deletions lib/Mojolicious.pm
Expand Up @@ -949,6 +949,8 @@ Nils Diewald
Oleg Zhelo
Olivier Mengue
Pascal Gaudette
Paul Evans
Expand Down
11 changes: 8 additions & 3 deletions t/mojo/json_pointer.t
Expand Up @@ -4,8 +4,9 @@ use Test::More;
use Mojo::JSON::Pointer;

# "contains" (hash)
my $pointer = Mojo::JSON::Pointer->new({foo => 23});
my $pointer = Mojo::JSON::Pointer->new({foo => 23, '' => 24});
ok $pointer->contains(''), 'contains ""';
ok $pointer->contains('/'), 'contains "/"';
ok $pointer->contains('/foo'), 'contains "/foo"';
ok !$pointer->contains('/bar'), 'does not contains "/bar"';
ok $pointer->new({foo => {bar => undef}})->contains('/foo/bar'),
Expand All @@ -18,15 +19,19 @@ ok $pointer->contains('/foo/0'), 'contains "/foo/0"';
ok !$pointer->contains('/foo/9'), 'does not contain "/foo/9"';
ok !$pointer->contains('/foo/bar'), 'does not contain "/foo/bar"';
ok !$pointer->contains('/0'), 'does not contain "/0"';
ok !$pointer->contains('/'), 'does not contain "/"';

# "get" (hash)
$pointer = Mojo::JSON::Pointer->new({foo => 'bar'});
is_deeply $pointer->get(''), {foo => 'bar'}, '"" is "{foo => "bar"}"';
$pointer = Mojo::JSON::Pointer->new({foo => 'bar', '' => 'baz'});
is_deeply $pointer->get(''), {foo => 'bar', '' => 'baz'},
'"" is "{foo => "bar", "" => "baz"}"';
is $pointer->get('/'), 'baz', '"/" is "baz"';
is $pointer->get('/foo'), 'bar', '"/foo" is "bar"';
is $pointer->new({foo => {bar => 42}})->get('/foo/bar'), 42,
'"/foo/bar" is "42"';
is_deeply $pointer->new({foo => {23 => {baz => 0}}})->get('/foo/23'),
{baz => 0}, '"/foo/23" is "{baz => 0}"';
is $pointer->new({foo => {'' => 42}})->get('/foo/'), 42, '"/foo/" is "42"';

# "get" (mixed)
is_deeply $pointer->new({foo => {bar => [1, 2, 3]}})->get('/foo/bar'),
Expand Down

0 comments on commit 9d05a4c

Please sign in to comment.