Subject: | Relaxed failure with comments at EOF |
Hi,
According to the documentation, the "relaxed" option causes JSON to
treat Perl style comments as whitespace. It fails to do so at end of file.
Attached is a test file that demonstrates the problem. Also attached is
the results of that test.
I'll try to provide a patch tomorrow.
- Eric
Subject: | comment_at_eof.t |
use strict;
use warnings;
use Test::More tests => 8;
use JSON -support_by_pp;
use Data::Dumper qw( Dumper );
sub decoder {
my ($str) = @_;
my $json = JSON->new()
->allow_barekey
->relaxed;
$json->incr_parse($_[0]);
my $rv;
if (!eval { $rv = $json->incr_parse(); 1 }) {
$rv = "died with $@";
}
local $Data::Dumper::Useqq = 1;
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Indent = 0;
return Dumper($rv);
}
is( decoder( "[]" ), '[]', 'array baseline' );
is( decoder( " []" ), '[]', 'space ignored before array' );
is( decoder( "\n[]" ), '[]', 'newline ignored before array' );
is( decoder( "# foo\n[]" ), '[]', 'comment ignored before array' );
is( decoder( "" ), 'undef', 'eof baseline' );
is( decoder( " " ), 'undef', 'space ignored before eof' );
is( decoder( "\n" ), 'undef', 'newline ignored before eof' );
is( decoder( "# foo\n" ), 'undef', 'comment ignored before eof' );
Subject: | test_results.txt |
1..8
ok 1 - array baseline
ok 2 - space ignored before array
ok 3 - newline ignored before array
ok 4 - comment ignored before array
ok 5 - eof baseline
ok 6 - space ignored before eof
ok 7 - newline ignored before eof
not ok 8 - comment ignored before eof
# Failed test 'comment ignored before eof'
# at comment_at_eof.t line 41.
# got: '"died with malformed JSON string, neither array, object, number, string or atom, at character offset 6 (before \"(end of string)\") at comment_at_eof.t line 21.\n"'
# expected: 'undef'
# Looks like you failed 1 test of 8.