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

Commit 1160402

Browse files
committed
Cpanel-JSON-XS-4.06
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.
1 parent b4282d9 commit 1160402

File tree

15 files changed

+436
-87
lines changed

15 files changed

+436
-87
lines changed

MANIFEST

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ cpan/Cpanel-JSON-XS/t/97_unshare_hek.t
436436
cpan/Cpanel-JSON-XS/t/98_56only.t
437437
cpan/Cpanel-JSON-XS/t/99_binary.t
438438
cpan/Cpanel-JSON-XS/t/_unicode_handling.pm
439-
cpan/Cpanel-JSON-XS/t/gh70-asan.t
440439
cpan/Cpanel-JSON-XS/t/zero-mojibake.t
441440
cpan/Cpanel-JSON-XS/typemap
442441
cpan/Cpanel-JSON-XS/XS.pm

META.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,5 @@
143143
}
144144
},
145145
"version" : "5.028000c",
146-
"x_serialization_backend" : "Cpanel::JSON::XS version 4.01"
146+
"x_serialization_backend" : "Cpanel::JSON::XS version 4.06"
147147
}

Porting/Maintainers.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ package Maintainers;
440440
},
441441

442442
'Cpanel::JSON::XS' => {
443-
'DISTRIBUTION' => 'RURBAN/Cpanel-JSON-XS-4.01.tar.gz',
443+
'DISTRIBUTION' => 'RURBAN/Cpanel-JSON-XS-4.06.tar.gz',
444444
'FILES' => q[cpan/Cpanel-JSON-XS],
445445
'EXCLUDED' => [
446446
'.appveyor.yml',
@@ -449,7 +449,7 @@ package Maintainers;
449449
'eg/bench',
450450
't/appveyor-test.bat',
451451
't/30_jsonspec.t',
452-
qr{^t/z_},
452+
qr{^xt/},
453453
qr{^t/test_(parsing|transform)},
454454
],
455455
},

cpan/Cpanel-JSON-XS/XS.pm

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package Cpanel::JSON::XS;
2-
our $VERSION = '4.01';
2+
our $VERSION = '4.06';
33
our $XS_VERSION = $VERSION;
44
# $VERSION = eval $VERSION;
55

@@ -530,6 +530,13 @@ resulting JSON text is guaranteed not to contain any C<newlines>.
530530
531531
This setting has no effect when decoding JSON texts.
532532
533+
=item $json = $json->indent_length([$number_of_spaces])
534+
535+
=item $length = $json->get_indent_length()
536+
537+
Set the indent length (default C<3>).
538+
This option is only useful when you also enable indent or pretty.
539+
The acceptable range is from 0 (no indentation) to 15
533540
534541
=item $json = $json->space_before ([$enable])
535542
@@ -1492,6 +1499,14 @@ directly if you want.
14921499
encode_json [Cpanel::JSON::XS::true, Cpanel::JSON::XS::true] # yields [false,true]
14931500
encode_json [!1, !0] # yields [false,true]
14941501
1502+
eq/ne comparisons with true, false:
1503+
1504+
false is eq to the empty string or the string 'false' or the special
1505+
empty string C<!!0>, i.e. C<SV_NO>, or the numbers 0 or 0.0.
1506+
1507+
true is eq to the string 'true' or to the special string C<!0>
1508+
(i.e. C<SV_YES>) or to the numbers 1 or 1.0.
1509+
14951510
=item blessed objects
14961511
14971512
Blessed objects are not directly representable in JSON, but
@@ -2209,14 +2224,24 @@ BEGIN {
22092224
"--" => sub { $_[0] = ${$_[0]} - 1 },
22102225
'""' => sub { ${$_[0]} == 1 ? '1' : '0' }, # GH 29
22112226
'eq' => sub {
2212-
my ($obj, $op) = ref ($_[0]) ? ($_[0], $_[1]) : ($_[1], $_[0]);
2213-
if ($op eq 'true' or $op eq 'false') {
2214-
return "$obj" eq '1' ? 'true' eq $op : 'false' eq $op;
2227+
my ($obj, $op) = $_[2] ? ($_[1], $_[0]) : ($_[0], $_[1]);
2228+
#warn "eq obj:$obj op:$op len:", length($op) > 0, " swap:$_[2]";
2229+
if (ref $op) { # if 2nd also blessed might recurse endlessly
2230+
return $obj ? 1 == $op : 0 == $op;
2231+
}
2232+
# if string, only accept numbers or true|false or "" (e.g. !!0 / SV_NO)
2233+
elsif ($op !~ /^[0-9]+$/) {
2234+
return "$obj" eq '1' ? 'true' eq $op : 'false' eq $op || "" eq $op;
22152235
}
22162236
else {
22172237
return $obj ? 1 == $op : 0 == $op;
22182238
}
22192239
},
2240+
'ne' => sub {
2241+
my ($obj, $op) = $_[2] ? ($_[1], $_[0]) : ($_[0], $_[1]);
2242+
#warn "ne obj:$obj op:$op";
2243+
return !($obj eq $op);
2244+
},
22202245
fallback => 1);
22212246
}
22222247

0 commit comments

Comments
 (0)