Skip to content

Commit

Permalink
updated for 2.52
Browse files Browse the repository at this point in the history
  • Loading branch information
makamaka committed May 22, 2011
1 parent 735a5e6 commit 38732e5
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 15 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ JSON distribution will inculde yet another JSON::PP modules.
They are JSNO::backportPP. So JSON.pm should work as it did at all!
--------------------------------------------------------------------------

2.52 Sun May 22 15:05:49 2011
- fixed to_json (pointed and patched by mmcleric in rt#68359)
- backport JSON::PP 2.27200
* fixed incr_parse docodeing string more correctly (rt#68032 by LCONS)

2.51 Tue Mar 8 16:03:34 2011
- import JSON::PP 2.27105 as BackportPP
- fixed documentations (pointed by Britton Kerin and rt#64738)
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ t/e12_upgrade.t
t/e13_overloaded_eq.t
t/e14_decode_prefix.t
t/e15_tie_ixhash.t
t/e16_incr_parse_fixed.t
t/e90_misc.t
t/x00_load.t
t/x02_error.t
t/x12_blessed.t
Expand Down
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ SYNOPSIS
# recommend to use (en|de)code_json.

VERSION
2.51
2.52

This version is compatible with JSON::XS 2.27 and later.

Expand Down Expand Up @@ -344,7 +344,7 @@ HOW DO I DECODE A DATA FROM OUTER AND ENCODE TO OUTER

COMMON OBJECT-ORIENTED INTERFACE
new
$json = new JSON
$json = JSON->new

Returns a new "JSON" object inherited from either JSON::XS or JSON::PP
that can be used to de/encode JSON strings.
Expand Down Expand Up @@ -1545,7 +1545,7 @@ AUTHOR
The relese of this new version owes to the courtesy of Marc Lehmann.

COPYRIGHT AND LICENSE
Copyright 2005-2010 by Makamaka Hannyaharamitu
Copyright 2005-2011 by Makamaka Hannyaharamitu

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Expand Down
8 changes: 4 additions & 4 deletions lib/JSON.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use base qw(Exporter);
@JSON::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_json);

BEGIN {
$JSON::VERSION = '2.51';
$JSON::VERSION = '2.52';
$JSON::DEBUG = 0 unless (defined $JSON::DEBUG);
$JSON::DEBUG = $ENV{ PERL_JSON_DEBUG } if exists $ENV{ PERL_JSON_DEBUG };
}

my $Module_XS = 'JSON::XS';
my $Module_PP = 'JSON::PP';
my $Module_bp = 'JSON::backportPP'; # included in JSON distribution
my $PP_Version = '2.27105';
my $PP_Version = '2.27200';
my $XS_Version = '2.27';


Expand Down Expand Up @@ -640,7 +640,7 @@ JSON - JSON (JavaScript Object Notation) encoder/decoder
=head1 VERSION
2.51
2.52
This version is compatible with JSON::XS B<2.27> and later.
Expand Down Expand Up @@ -2258,7 +2258,7 @@ The relese of this new version owes to the courtesy of Marc Lehmann.
=head1 COPYRIGHT AND LICENSE
Copyright 2005-2010 by Makamaka Hannyaharamitu
Copyright 2005-2011 by Makamaka Hannyaharamitu
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Expand Down
21 changes: 13 additions & 8 deletions lib/JSON/backportPP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Carp ();
use B ();
#use Devel::Peek;

$JSON::PP::VERSION = '2.27105';
$JSON::PP::VERSION = '2.27200';

@JSON::PP::EXPORT = qw(encode_json decode_json from_json to_json);

Expand Down Expand Up @@ -1462,7 +1462,7 @@ sub incr_parse {

if ( defined wantarray ) {

$self->{incr_mode} = INCR_M_WS;
$self->{incr_mode} = INCR_M_WS unless defined $self->{incr_mode};

if ( wantarray ) {
my @ret;
Expand All @@ -1473,10 +1473,10 @@ sub incr_parse {
push @ret, $self->_incr_parse( $coder, $self->{incr_text} );

unless ( !$self->{incr_nest} and $self->{incr_mode} == INCR_M_JSON ) {
$self->{incr_mode} = INCR_M_WS;
$self->{incr_mode} = INCR_M_WS if $self->{incr_mode} != INCR_M_STR;
}

} until ( !$self->{incr_text} );
} until ( length $self->{incr_text} >= $self->{incr_p} );

$self->{incr_parsing} = 0;

Expand Down Expand Up @@ -1515,6 +1515,10 @@ sub _incr_parse {
my $s = substr( $text, $p++, 1 );

if ( $s eq '"' ) {
if (substr( $text, $p - 2, 1 ) eq '\\' ) {
next;
}

if ( $self->{incr_mode} != INCR_M_STR ) {
$self->{incr_mode} = INCR_M_STR;
}
Expand Down Expand Up @@ -1548,6 +1552,7 @@ sub _incr_parse {

$self->{incr_p} = $p;

return if ( $self->{incr_mode} == INCR_M_STR and not $self->{incr_nest} );
return if ( $self->{incr_mode} == INCR_M_JSON and $self->{incr_nest} > 0 );

return '' unless ( length substr( $self->{incr_text}, 0, $p ) );
Expand Down Expand Up @@ -1628,9 +1633,9 @@ JSON::PP - JSON::XS compatible pure-Perl module.
=head1 VERSION
2.27105
2.27200
L<JSON::XS> 2.27 compatible.
L<JSON::XS> 2.27 (~2.30) compatible.
=head1 DESCRIPTION
Expand Down Expand Up @@ -1806,7 +1811,7 @@ Basically, check to L<JSON> or L<JSON::XS>.
=head2 new
$json = new JSON::PP
$json = JSON::PP->new
Rturns a new JSON::PP object that can be used to de/encode JSON
strings.
Expand Down Expand Up @@ -2784,7 +2789,7 @@ Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2007-2010 by Makamaka Hannyaharamitu
Copyright 2007-2011 by Makamaka Hannyaharamitu
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Expand Down
29 changes: 29 additions & 0 deletions t/e16_incr_parse_fixed.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/perl

BEGIN {
$ENV{ PERL_JSON_BACKEND } = $ARGV[0] || 'JSON::backportPP';
}

use strict;
use Test::More tests => 4;

use JSON;

my $json = JSON->new->allow_nonref();

my @vs = $json->incr_parse('"a\"bc');

ok( not scalar(@vs) );

@vs = $json->incr_parse('"');

is( $vs[0], "a\"bc" );


$json = JSON->new;

@vs = $json->incr_parse('"a\"bc');
ok( not scalar(@vs) );
@vs = eval { $json->incr_parse('"') };
ok($@ =~ qr/JSON text must be an object or array/);

19 changes: 19 additions & 0 deletions t/e90_misc.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/perl

use strict;
use Test::More tests => 4;

BEGIN {
$ENV{ PERL_JSON_BACKEND } = $ARGV[0] || 'JSON::backportPP';
}

use JSON;

# reported by https://rt.cpan.org/Public/Bug/Display.html?id=68359

eval { JSON->to_json( 5, { allow_nonref => 1 } ) };
ok($@);

is( q{"5"}, JSON::to_json( "5", { allow_nonref => 1 } ) );
is( q{5}, JSON::to_json( 5, { allow_nonref => 1 } ) );
is( q{"JSON"}, JSON::to_json( 'JSON', { allow_nonref => 1 } ) );

0 comments on commit 38732e5

Please sign in to comment.