Skip Menu |

This queue is for tickets about the JSON-PP CPAN distribution.

Report information
The Basics
Id: 116998
Status: resolved
Priority: 0/
Queue: JSON-PP

People
Owner: Nobody in particular
Requestors: ilmari+cpan [...] ilmari.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Wrong character offset for syntax errors
If there's a missing } at the end of the string when parsing an object, the error location points one character too early: $ perl -MJSON::PP -e 'decode_json(qq({"foo":{"bar":42}))' , or } expected while parsing object/hash, at character offset 16 (before "}") at -e line 1. If the missing character is ], it gets it right: $ perl -MJSON::PP -e 'decode_json(qq(["foo",{"bar":42}))' , or ] expected while parsing array, at character offset 17 (before "(end of string)") at -e line 1. But an unexpected " when parsing an array is off by one the other direction: $ perl -MJSON::PP -e 'decode_json(qq(["foo",{"bar":42}"]))' , or ] expected while parsing array, at character offset 18 (before "]") at -e line 1. While an unexpected " when parsing an object is correct: $ perl -MJSON::PP -e 'decode_json(qq({"foo":{"bar":42}"}))' , or } expected while parsing object/hash, at character offset 17 (before ""}") at -e line 1. These are just some of the errors I've found in a few minutes of experimentation. There may be more.
On Tue Aug 16 22:54:30 2016, ilmari wrote: Show quoted text
> If there's a missing } at the end of the string when parsing an > object, the error location points one character too early: > > $ perl -MJSON::PP -e 'decode_json(qq({"foo":{"bar":42}))' > , or } expected while parsing object/hash, at character offset 16 > (before "}") at -e line 1. > > If the missing character is ], it gets it right: > > $ perl -MJSON::PP -e 'decode_json(qq(["foo",{"bar":42}))' > , or ] expected while parsing array, at character offset 17 (before > "(end of string)") at -e line 1. > > But an unexpected " when parsing an array is off by one the other > direction: > > $ perl -MJSON::PP -e 'decode_json(qq(["foo",{"bar":42}"]))' > , or ] expected while parsing array, at character offset 18 (before > "]") at -e line 1. > > While an unexpected " when parsing an object is correct: > > $ perl -MJSON::PP -e 'decode_json(qq({"foo":{"bar":42}"}))' > , or } expected while parsing object/hash, at character offset 17 > (before ""}") at -e line 1. > > These are just some of the errors I've found in a few minutes of > experimentation. There may be more.
Thanks for spotting these. What you've mentioned above are fixed in the master. I'll compare PP code with other implementations to see if there's more. https://github.com/makamaka/JSON-PP/commit/322e809ceb9b1933dd72171d779280c37d9fb2f3
On Sun Oct 09 02:19:38 2016, ISHIGAKI wrote: Show quoted text
> On Tue Aug 16 22:54:30 2016, ilmari wrote:
> > If there's a missing } at the end of the string when parsing an > > object, the error location points one character too early: > > > > $ perl -MJSON::PP -e 'decode_json(qq({"foo":{"bar":42}))' > > , or } expected while parsing object/hash, at character offset 16 > > (before "}") at -e line 1. > > > > If the missing character is ], it gets it right: > > > > $ perl -MJSON::PP -e 'decode_json(qq(["foo",{"bar":42}))' > > , or ] expected while parsing array, at character offset 17 (before > > "(end of string)") at -e line 1. > > > > But an unexpected " when parsing an array is off by one the other > > direction: > > > > $ perl -MJSON::PP -e 'decode_json(qq(["foo",{"bar":42}"]))' > > , or ] expected while parsing array, at character offset 18 (before > > "]") at -e line 1. > > > > While an unexpected " when parsing an object is correct: > > > > $ perl -MJSON::PP -e 'decode_json(qq({"foo":{"bar":42}"}))' > > , or } expected while parsing object/hash, at character offset 17 > > (before ""}") at -e line 1. > > > > These are just some of the errors I've found in a few minutes of > > experimentation. There may be more.
> > Thanks for spotting these. What you've mentioned above are fixed in > the master. I'll compare PP code with other implementations to see if > there's more. > > https://github.com/makamaka/JSON- > PP/commit/322e809ceb9b1933dd72171d779280c37d9fb2f3
Closed as 2.92 was released. Thanks.