Skip to content

Commit

Permalink
Fix regression decoding big strings
Browse files Browse the repository at this point in the history
for strings >16384. Fixes #50, reported by Dan Book.
  • Loading branch information
Reini Urban committed Dec 2, 2015
1 parent be4237d commit ee74614
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Revision history for Perl extension Cpanel::JSON::XS

TODO: http://stevehanov.ca/blog/index.php?id=104 compression

3.0207 2015-12-02 (rurban)
- Fix regression decoding big strings (>16384). #50 (reported by Dan Book)
- Ignore allow_barekey if we detect quotes. #51 (Fixed by Quim Rovira)
- Skip some unicode tests with 5.6

3.0206 2015-11-30 (rurban)
- Add support for escape_slash from JSON::PP. #47
- Map sort_by to canonical from JSON::PP. #47
Expand Down
2 changes: 1 addition & 1 deletion XS.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Cpanel::JSON::XS;
our $VERSION = '3.0206';
our $VERSION = '3.0207';

=pod
Expand Down
2 changes: 1 addition & 1 deletion XS.xs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ _decode_str (pTHX_ dec_t *dec, char endstr)
sv = newSVpvn (buf, len);
}
}
while (*dec_cur != ch);
while (*dec_cur != endstr);

++dec_cur;

Expand Down
34 changes: 22 additions & 12 deletions t/108_decode.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
# decode on Perl 5.005, 5.6, 5.8 or later
#
use strict;
use Test::More tests => 6;
use Test::More tests => 8;

use Cpanel::JSON::XS;

BEGIN {
use lib qw(t);
use _unicode_handling;
}

use lib qw(t);
use _unicode_handling;
no utf8;

my $json = Cpanel::JSON::XS->new->allow_nonref;
Expand All @@ -23,17 +19,31 @@ is($json->decode(q|"\u00fc"|), "\xfc"); # latin1
is($json->decode(q|"\u00c3\u00bc"|), "\xc3\xbc"); # utf8

my $str = ''; # Japanese 'a' in utf8

is($json->decode(q|"\u00e3\u0081\u0082"|), $str);

utf8::decode($str) if $] > 5.007; # usually UTF-8 flagged on, but no-op for 5.005.

is($json->decode(q|"\u3042"|), $str);


my $utf8 = $json->decode(q|"\ud808\udf45"|); # chr 12345

utf8::encode($utf8) if $] > 5.007; # UTf-8 flaged off

is($utf8, "\xf0\x92\x8d\x85");

# GH#50 decode >SHORT_STRING_LEN (16384) broken with 3.0206
my $bytes = encode_json(["a" x 32768]);
my $decode = eval { decode_json($bytes); };

ok(!$@, "can decode big string $@");
is_deeply $decode, ["a" x 32768], "successful roundtrip"

or do {
my $fh;
open $fh, '>', 'encode.json' or die $!;
#END { unlink('encode.json'); }
print $fh $bytes;
close $fh;
open $fh, '>', 'decode.jxt' or die $!;
#END { unlink('decode.txt'); }
print $fh decode_json($bytes);
close $fh;
};

0 comments on commit ee74614

Please sign in to comment.