Skip to content

Commit

Permalink
fix wrong character offsets spotted by ilmari (RT-116998)
Browse files Browse the repository at this point in the history
  • Loading branch information
charsbar committed Oct 8, 2016
1 parent 9f4c9df commit 322e809
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/JSON/PP.pm
Expand Up @@ -930,6 +930,7 @@ BEGIN {
}
}

$at-- if defined $ch and $ch ne '';
decode_error(", or ] expected while parsing array");
}

Expand Down Expand Up @@ -996,7 +997,7 @@ BEGIN {

}

$at--;
$at-- if defined $ch and $ch ne '';
decode_error(", or } expected while parsing object/hash");
}

Expand Down
18 changes: 18 additions & 0 deletions t/rt_116998_wrong_character_offset.t
@@ -0,0 +1,18 @@
use strict;
use Test::More;
BEGIN { plan tests => 4 };
BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
use JSON::PP;

eval { decode_json(qq({"foo":{"bar":42})) };
like $@ => qr/offset 17/; # 16

eval { decode_json(qq(["foo",{"bar":42})) };
like $@ => qr/offset 17/;

eval { decode_json(qq(["foo",{"bar":42}"])) };
like $@ => qr/offset 17/; # 18

eval { decode_json(qq({"foo":{"bar":42}"})) };
like $@ => qr/offset 17/;

0 comments on commit 322e809

Please sign in to comment.