Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Cpanel-JSON-XS-4.06
Browse files Browse the repository at this point in the history
4.06 2018-08-22 (rurban)
        - Fix overloaded eq/ne comparisons (GH #116 by demerphq, GH #117 by Graham Knopp):
          detect strings, protect from endless recursion. false is now ne "True".
          clarify eq/ne rules in the docs.

4.05 2018-08-19 (rurban)
        - Set decoded type (PR #115 by Pali)
        - Add json_type_weaken (PR #114 by Pali)
        - Fix tests for 5.6 (rurban, pali)

4.04 2018-06-22 (rurban)
        - Fix bignum NaN/inf handling (#78 reported by Slaven Rezic)
        - Move author tests to xt/ as suggested in #106, added a make xtest target.
          Fixes a test fail with ASAN.

4.03 2018-06-21 (rurban)
        - Add sereal cpanel_json_xs type (#110 James Rouzier)
        - Fix bencode/bdecode methods in cpanel_json_xs (#111 Fulvio Scapin)
        - Overload ne operator for JSON::PP::Boolean (#107 tevfik1903)
        - Add a missing semicolon to a documentation example (#104 E. Choroba)

4.02 2018-02-27 (rurban)
        - Add encoder indent_length method (#103 rouzier), previously
          hard-coded to 3.
  • Loading branch information
rurban committed Aug 27, 2018
1 parent b4282d9 commit 1160402
Show file tree
Hide file tree
Showing 15 changed files with 436 additions and 87 deletions.
1 change: 0 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ cpan/Cpanel-JSON-XS/t/97_unshare_hek.t
cpan/Cpanel-JSON-XS/t/98_56only.t
cpan/Cpanel-JSON-XS/t/99_binary.t
cpan/Cpanel-JSON-XS/t/_unicode_handling.pm
cpan/Cpanel-JSON-XS/t/gh70-asan.t
cpan/Cpanel-JSON-XS/t/zero-mojibake.t
cpan/Cpanel-JSON-XS/typemap
cpan/Cpanel-JSON-XS/XS.pm
Expand Down
2 changes: 1 addition & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@
}
},
"version" : "5.028000c",
"x_serialization_backend" : "Cpanel::JSON::XS version 4.01"
"x_serialization_backend" : "Cpanel::JSON::XS version 4.06"
}
4 changes: 2 additions & 2 deletions Porting/Maintainers.pl
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ package Maintainers;
},

'Cpanel::JSON::XS' => {
'DISTRIBUTION' => 'RURBAN/Cpanel-JSON-XS-4.01.tar.gz',
'DISTRIBUTION' => 'RURBAN/Cpanel-JSON-XS-4.06.tar.gz',
'FILES' => q[cpan/Cpanel-JSON-XS],
'EXCLUDED' => [
'.appveyor.yml',
Expand All @@ -449,7 +449,7 @@ package Maintainers;
'eg/bench',
't/appveyor-test.bat',
't/30_jsonspec.t',
qr{^t/z_},
qr{^xt/},
qr{^t/test_(parsing|transform)},
],
},
Expand Down
33 changes: 29 additions & 4 deletions cpan/Cpanel-JSON-XS/XS.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Cpanel::JSON::XS;
our $VERSION = '4.01';
our $VERSION = '4.06';
our $XS_VERSION = $VERSION;
# $VERSION = eval $VERSION;

Expand Down Expand Up @@ -530,6 +530,13 @@ resulting JSON text is guaranteed not to contain any C<newlines>.
This setting has no effect when decoding JSON texts.
=item $json = $json->indent_length([$number_of_spaces])
=item $length = $json->get_indent_length()
Set the indent length (default C<3>).
This option is only useful when you also enable indent or pretty.
The acceptable range is from 0 (no indentation) to 15
=item $json = $json->space_before ([$enable])
Expand Down Expand Up @@ -1492,6 +1499,14 @@ directly if you want.
encode_json [Cpanel::JSON::XS::true, Cpanel::JSON::XS::true] # yields [false,true]
encode_json [!1, !0] # yields [false,true]
eq/ne comparisons with true, false:
false is eq to the empty string or the string 'false' or the special
empty string C<!!0>, i.e. C<SV_NO>, or the numbers 0 or 0.0.
true is eq to the string 'true' or to the special string C<!0>
(i.e. C<SV_YES>) or to the numbers 1 or 1.0.
=item blessed objects
Blessed objects are not directly representable in JSON, but
Expand Down Expand Up @@ -2209,14 +2224,24 @@ BEGIN {
"--" => sub { $_[0] = ${$_[0]} - 1 },
'""' => sub { ${$_[0]} == 1 ? '1' : '0' }, # GH 29
'eq' => sub {
my ($obj, $op) = ref ($_[0]) ? ($_[0], $_[1]) : ($_[1], $_[0]);
if ($op eq 'true' or $op eq 'false') {
return "$obj" eq '1' ? 'true' eq $op : 'false' eq $op;
my ($obj, $op) = $_[2] ? ($_[1], $_[0]) : ($_[0], $_[1]);
#warn "eq obj:$obj op:$op len:", length($op) > 0, " swap:$_[2]";
if (ref $op) { # if 2nd also blessed might recurse endlessly
return $obj ? 1 == $op : 0 == $op;
}
# if string, only accept numbers or true|false or "" (e.g. !!0 / SV_NO)
elsif ($op !~ /^[0-9]+$/) {
return "$obj" eq '1' ? 'true' eq $op : 'false' eq $op || "" eq $op;
}
else {
return $obj ? 1 == $op : 0 == $op;
}
},
'ne' => sub {
my ($obj, $op) = $_[2] ? ($_[1], $_[0]) : ($_[0], $_[1]);
#warn "ne obj:$obj op:$op";
return !($obj eq $op);
},
fallback => 1);
}

Expand Down
Loading

0 comments on commit 1160402

Please sign in to comment.