Hello community,
here is the log from the commit of package perl-Cpanel-JSON-XS for openSUSE:Factory checked in at 2018-08-31 10:44:07
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Cpanel-JSON-XS (Old)
and /work/SRC/openSUSE:Factory/.perl-Cpanel-JSON-XS.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Cpanel-JSON-XS"
Fri Aug 31 10:44:07 2018 rev:13 rq:631780 version:4.06
Changes:
--------
--- /work/SRC/openSUSE:Factory/perl-Cpanel-JSON-XS/perl-Cpanel-JSON-XS.changes 2018-06-28 15:15:06.847406556 +0200
+++ /work/SRC/openSUSE:Factory/.perl-Cpanel-JSON-XS.new/perl-Cpanel-JSON-XS.changes 2018-08-31 10:44:35.899213589 +0200
@@ -1,0 +2,22 @@
+Sat Aug 25 05:11:03 UTC 2018 - coolo@suse.com
+
+- updated to 4.06
+ see /usr/share/doc/packages/perl-Cpanel-JSON-XS/Changes
+
+ 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.
+
+-------------------------------------------------------------------
+Mon Aug 20 05:13:07 UTC 2018 - coolo@suse.com
+
+- updated to 4.05
+ see /usr/share/doc/packages/perl-Cpanel-JSON-XS/Changes
+
+ 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)
+
+-------------------------------------------------------------------
Old:
----
Cpanel-JSON-XS-4.04.tar.gz
New:
----
Cpanel-JSON-XS-4.06.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-Cpanel-JSON-XS.spec ++++++
--- /var/tmp/diff_new_pack.Tur6A3/_old 2018-08-31 10:44:37.211215161 +0200
+++ /var/tmp/diff_new_pack.Tur6A3/_new 2018-08-31 10:44:37.215215166 +0200
@@ -17,7 +17,7 @@
Name: perl-Cpanel-JSON-XS
-Version: 4.04
+Version: 4.06
Release: 0
%define cpan_name Cpanel-JSON-XS
Summary: Cpanel Fork of Json::Xs, Fast and Correct Serializing
++++++ Cpanel-JSON-XS-4.04.tar.gz -> Cpanel-JSON-XS-4.06.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/.travis.yml new/Cpanel-JSON-XS-4.06/.travis.yml
--- old/Cpanel-JSON-XS-4.04/.travis.yml 2018-06-21 16:33:40.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/.travis.yml 2018-08-19 18:54:16.000000000 +0200
@@ -1,7 +1,7 @@
language: "perl"
sudo: false
perl:
-# - "5.6.2"
+ - "5.6.2"
- "5.8"
- "5.10"
- "5.12"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/Changes new/Cpanel-JSON-XS-4.06/Changes
--- old/Cpanel-JSON-XS-4.04/Changes 2018-06-22 19:34:07.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/Changes 2018-08-23 09:49:34.000000000 +0200
@@ -2,6 +2,16 @@
TODO: http://stevehanov.ca/blog/index.php?id=104 compression
+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.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/META.json new/Cpanel-JSON-XS-4.06/META.json
--- old/Cpanel-JSON-XS-4.04/META.json 2018-06-22 19:36:41.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/META.json 2018-08-23 09:49:54.000000000 +0200
@@ -4,7 +4,7 @@
"Reini Urban "
],
"dynamic_config" : 1,
- "generated_by" : "ExtUtils::MakeMaker version 8.3004, CPAN::Meta::Converter version 2.150010",
+ "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
@@ -48,7 +48,7 @@
"url" : "https://github.com/rurban/Cpanel-JSON-XS"
}
},
- "version" : "4.04",
+ "version" : "4.06",
"x_contributors" : [
"Ashley Willis ",
"Daniel Dragan ",
@@ -73,5 +73,5 @@
"Sergey Aleynikov ",
"Syohei Yoshida "
],
- "x_serialization_backend" : "JSON::PP version 2.97001_04"
+ "x_serialization_backend" : "JSON::PP version 2.97001"
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/META.yml new/Cpanel-JSON-XS-4.06/META.yml
--- old/Cpanel-JSON-XS-4.04/META.yml 2018-06-22 19:36:41.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/META.yml 2018-08-23 09:49:54.000000000 +0200
@@ -7,7 +7,7 @@
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 8.3004, CPAN::Meta::Converter version 2.150010'
+generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -23,7 +23,7 @@
bugtracker: https://github.com/rurban/Cpanel-JSON-XS/issues
license: http://dev.perl.org/licenses/
repository: https://github.com/rurban/Cpanel-JSON-XS
-version: '4.04'
+version: '4.06'
x_contributors:
- 'Ashley Willis '
- 'Daniel Dragan '
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/README new/Cpanel-JSON-XS-4.06/README
--- old/Cpanel-JSON-XS-4.04/README 2018-06-22 19:36:42.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/README 2018-08-23 09:49:56.000000000 +0200
@@ -1336,6 +1336,14 @@
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 "!!0", i.e. "SV_NO", or the numbers 0 or 0.0.
+
+ true is eq to the string 'true' or to the special string "!0" (i.e.
+ "SV_YES") or to the numbers 1 or 1.0.
+
blessed objects
Blessed objects are not directly representable in JSON, but
"Cpanel::JSON::XS" allows various optional ways of handling objects.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/SIGNATURE new/Cpanel-JSON-XS-4.06/SIGNATURE
--- old/Cpanel-JSON-XS-4.04/SIGNATURE 2018-06-22 19:36:41.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/SIGNATURE 2018-08-23 09:49:55.000000000 +0200
@@ -12,21 +12,21 @@
not run its Makefile.PL or Build.PL.
-----BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
+Hash: SHA256
SHA1 b1dc76bb84e636c3d4a32dc6676ae3259fa25aeb .appveyor.yml
-SHA1 216a7f89ddc0c8baa19bc1072d5c2eb485f9c833 .travis.yml
+SHA1 65fc21ade6dae1e18b4781332953cf481fb28718 .travis.yml
SHA1 9a56f3b919dfc8fced3803e165a2e38de62646e5 COPYING
-SHA1 33f36aeb4f23b9955fdd1cfceb05a472aa9bb8b6 Changes
+SHA1 13b9475237d825f194ced4efc720b5d0240decaa Changes
SHA1 2155ef71c1f88c6cd2805c5577b7793e45f80767 MANIFEST
-SHA1 d0137c5a756db9f8d230bb26ae310b5af35900ee META.json
-SHA1 ea9908e2535d67b2281dff02d7b2c3661dd68c33 META.yml
+SHA1 faca13a2019f7b693e1043032196a3268204b1fa META.json
+SHA1 e6888be4c11a1931aaec448ca726a3532c1b43b0 META.yml
SHA1 9dafd87f1da5bdb765a113da4dc7d8020a6fc385 Makefile.PL
-SHA1 47bd851360546d3ba5f3af787396efb6ef5b698c README
-SHA1 1d53a5249f2402c5ac1a6dbbeea2582cea958824 XS.pm
-SHA1 b19eb17322ddb70c7712bc21f0edac831c92fe71 XS.xs
+SHA1 efded39f8982feb36665b533cdd89b7df9d3b671 README
+SHA1 9bed9da89d91aca66723c941348f59045384a4a3 XS.pm
+SHA1 4638f6fbf6c4a0bbb99b17cc60383a867cc4e743 XS.xs
SHA1 04d2fb4de419fdd82b8e9837a939bb55ee4b478a XS/Boolean.pm
-SHA1 2e4fa239d50b9f4e692143b49b4a355de91d1348 XS/Type.pm
+SHA1 99a53c8302d508456a1b18c3c8d10e337d3a8414 XS/Type.pm
SHA1 7a3ec155fe1cd51bc4bf17bb3b0b5d4520439de1 bin/cpanel_json_xs
SHA1 ea72bbe602baaabdd0004ef1d7e7cc3334b42bb4 eg/bench
SHA1 6e5d2153e1931be4e416c8feef7f7dfcab0f91b4 ppport.h
@@ -50,12 +50,12 @@
SHA1 849b88cb5f17ca6c2324c78e1c4cb1d7857caccb t/10_pc_keysort.t
SHA1 ce50db81e59cca22ad32947f0dacaca7dca5212d t/110_bignum.t
SHA1 b007b686bb590e5eed3976edc78310437ae169d4 t/112_upgrade.t
-SHA1 01a0a0644343059c7185cb0b3b00b869d5211e1d t/113_overloaded_eq.t
+SHA1 84415f2662f91f3c3e2136a31c2e8ec441416077 t/113_overloaded_eq.t
SHA1 8dece990d5b07df0ae1b6364caefced774cb587d t/114_decode_prefix.t
SHA1 eb050780996f1e428c87bf6375415ca4c863cbb2 t/115_tie_ixhash.t
SHA1 3477b0490b8666e451ac15df97f9f35d72c946b1 t/116_incr_parse_fixed.t
SHA1 25ca035b576130cf560953df4e9daf68bdd96c3c t/117_numbers.t
-SHA1 0370aa1cb4188804d66bdf2e33fb9554210db786 t/118_type.t
+SHA1 7cd7abab7deaa77d5b0cbe7526a85bb0b5ba1dad t/118_type.t
SHA1 d1003d09b5da3609977362bcda64b2c593039a6b t/11_pc_expo.t
SHA1 c0037e62cefc891df4bb84a110051963a60e9f8c t/12_blessed.t
SHA1 4d553fd6b5e4486f087babff2946e0cb4b2c38fb t/13_limit.t
@@ -437,7 +437,12 @@
SHA1 8db603172315dd0853ecc383dba4945c5b673e8f xt/pod.t
-----BEGIN PGP SIGNATURE-----
-iF0EARECAB0WIQRZHhhUcL58V8z0UW2abZJij/3JQgUCWy0zqQAKCRCabZJij/3J
-QppPAJ9FbDAYbUxQ5BujNq6U+UGUgsYgIACePLJyw6GOSLjSKUMbZedtbKPU5is=
-=QG3H
+iQEzBAEBCAAdFiEEKJWogdNCcPq/6PdHtPYzOeZdZBQFAlt+ZyMACgkQtPYzOeZd
+ZBR90gf/QGaE6b7YyYYzHChR+kprK6K3mIqX8RmFPa9OxOaXZCnw9baVrQH52YrO
+dom7nQKS/Fhm/cRB5r4SYMuttKWgV+v2huDq2FuNz4opCQBkCgHFN1vR30O1UW3o
+g487cMxvyUXFuey1KOAS2FAQ0Y1nmUmkl87iGeSnBQJdsa5z3biB6VesUht+xfWj
+//VbqV+d3Gm1DrrFHnzyTsCBmnMDg3yunGB/GOhNyyxB2zDXmiEfacXFg2ae0MK9
+PSeTEc2q1Jb5IgB4h/F6R4g8KYmh77eAvWGomenRkeJGVxHttH+PGt3oNIXDrxCi
+2JAgZcuoe+wgxS5agKCfNGssfm3gEw==
+=pos6
-----END PGP SIGNATURE-----
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/XS/Type.pm new/Cpanel-JSON-XS-4.06/XS/Type.pm
--- old/Cpanel-JSON-XS-4.04/XS/Type.pm 2018-06-21 13:18:27.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/XS/Type.pm 2018-08-19 18:54:16.000000000 +0200
@@ -11,6 +11,7 @@
use Cpanel::JSON::XS;
use Cpanel::JSON::XS::Type;
+
encode_json([10, "10", 10.25], [JSON_TYPE_INT, JSON_TYPE_INT, JSON_TYPE_STRING]);
# '[10,10,"10.25"]'
@@ -35,11 +36,27 @@
my $json_string = encode_json($perl_struct, $type_spec);
# '{"key1":{"key2":[10,10,10]},"key3":10.5}'
+
+ my $value = decode_json('false', 1, my $type);
+ # $value is 0 and $type is JSON_TYPE_BOOL
+
+ my $value = decode_json('0', 1, my $type);
+ # $value is 0 and $type is JSON_TYPE_INT
+
+ my $value = decode_json('"0"', 1, my $type);
+ # $value is 0 and $type is JSON_TYPE_STRING
+
+ my $json_string = '{"key1":{"key2":[10,"10",10.6]},"key3":"10.5"}';
+ my $perl_struct = decode_json($json_string, 0, my $type_spec);
+ # $perl_struct is { key1 => { key2 => [ 10, 10, 10.6 ] }, key3 => 10.5 }
+ # $type_spec is { key1 => { key2 => [ JSON_TYPE_INT, JSON_TYPE_STRING, JSON_TYPE_FLOAT ] }, key3 => JSON_TYPE_STRING }
+
=head1 DESCRIPTION
This module provides stable JSON type support for the
LCpanel::JSON::XS|Cpanel::JSON::XS encoder which doesn't depend on
-any internal perl scalar flags or characteristics.
+any internal perl scalar flags or characteristics. Also it provides
+real JSON types for LCpanel::JSON::XS|Cpanel::JSON::XS decoder.
In most cases perl structures passed to
L come from other functions
@@ -48,6 +65,12 @@
easy to support enforcing types as described in the
L section.
+For services based on JSON contents it is sometimes needed to correctly
+process and enforce JSON types.
+
+The function L takes optional
+third scalar parameter and fills it with specification of json types.
+
The function L takes a perl
structure as its input and optionally also a json type specification in
the second parameter.
@@ -84,6 +107,11 @@
It enforces JSON string type in the resulting JSON.
+=item JSON_TYPE_NULL
+
+It represents JSON C<null> value. Makes sense only when passing
+perl's C<undef> value.
+
=back
For each type, there also exists a type with the suffix C<_OR_NULL>
@@ -142,8 +170,29 @@
Like L|/json_type_anyof>, but scalar can be only
perl's C<undef>.
+=item json_type_weaken
+
+This function can be used as an argument for L,
+L or L functions to create weak
+references suitable for complicated recursive structures. It depends
+on L module.
+See following example:
+
+ my $struct = {
+ type => JSON_TYPE_STRING,
+ array => json_type_arrayof(JSON_TYPE_INT),
+ };
+ $struct->{recursive} = json_type_anyof(
+ json_type_weaken($struct),
+ json_type_arrayof(JSON_TYPE_STRING),
+ );
+
=back
+=head1 AUTHOR
+
+Pali E<lt>pali@cpan.orgE<gt>
+
=head1 COPYRIGHT & LICENSE
Copyright (c) 2017, GoodData Corporation. All rights reserved.
@@ -156,6 +205,14 @@
use strict;
use warnings;
+BEGIN {
+ if (eval { require Scalar::Util }) {
+ Scalar::Util->import('weaken');
+ } else {
+ *weaken = sub($) { die 'Scalar::Util is required for weaken' };
+ }
+}
+
# This exports needed XS constants to perl
use Cpanel::JSON::XS ();
@@ -166,6 +223,8 @@
json_type_hashof
json_type_anyof
json_type_null_or_anyof
+ json_type_weaken
+ JSON_TYPE_NULL
JSON_TYPE_BOOL
JSON_TYPE_INT
JSON_TYPE_FLOAT
@@ -179,24 +238,41 @@
JSON_TYPE_ANYOF_CLASS
);
+use constant JSON_TYPE_WEAKEN_CLASS => 'Cpanel::JSON::XS::Type::Weaken';
+
sub json_type_anyof {
my ($scalar, $array, $hash);
+ my ($scalar_weaken, $array_weaken, $hash_weaken);
foreach (@_) {
- my $type = ref($_);
- if ($type eq '') {
+ my $type = $_;
+ my $ref = ref($_);
+ my $weaken;
+ if ($ref eq JSON_TYPE_WEAKEN_CLASS) {
+ $type = ${$type};
+ $ref = ref($type);
+ $weaken = 1;
+ }
+ if ($ref eq '') {
die 'Only one scalar type can be specified in anyof' if defined $scalar;
- $scalar = $_;
- } elsif ($type eq 'ARRAY' or $type eq JSON_TYPE_ARRAYOF_CLASS) {
+ $scalar = $type;
+ $scalar_weaken = $weaken;
+ } elsif ($ref eq 'ARRAY' or $ref eq JSON_TYPE_ARRAYOF_CLASS) {
die 'Only one array type can be specified in anyof' if defined $array;
- $array = $_;
- } elsif ($type eq 'HASH' or $type eq JSON_TYPE_HASHOF_CLASS) {
+ $array = $type;
+ $array_weaken = $weaken;
+ } elsif ($ref eq 'HASH' or $ref eq JSON_TYPE_HASHOF_CLASS) {
die 'Only one hash type can be specified in anyof' if defined $hash;
- $hash = $_;
+ $hash = $type;
+ $hash_weaken = $weaken;
} else {
die 'Only scalar, array or hash can be specified in anyof';
}
}
- return bless [$scalar, $array, $hash], JSON_TYPE_ANYOF_CLASS;
+ my $type = [$scalar, $array, $hash];
+ weaken $type->[0] if $scalar_weaken;
+ weaken $type->[1] if $array_weaken;
+ weaken $type->[2] if $hash_weaken;
+ return bless $type, JSON_TYPE_ANYOF_CLASS;
}
sub json_type_null_or_anyof {
@@ -208,12 +284,28 @@
sub json_type_arrayof {
die 'Exactly one type must be specified in arrayof' if scalar @_ != 1;
- return bless \(my $type = $_[0]), JSON_TYPE_ARRAYOF_CLASS;
+ my $type = $_[0];
+ if (ref($type) eq JSON_TYPE_WEAKEN_CLASS) {
+ $type = ${$type};
+ weaken $type;
+ }
+ return bless \$type, JSON_TYPE_ARRAYOF_CLASS;
}
sub json_type_hashof {
die 'Exactly one type must be specified in hashof' if scalar @_ != 1;
- return bless \(my $type = $_[0]), JSON_TYPE_HASHOF_CLASS;
+ my $type = $_[0];
+ if (ref($type) eq JSON_TYPE_WEAKEN_CLASS) {
+ $type = ${$type};
+ weaken $type;
+ }
+ return bless \$type, JSON_TYPE_HASHOF_CLASS;
+}
+
+sub json_type_weaken {
+ die 'Exactly one type must be specified in weaken' if scalar @_ != 1;
+ die 'Scalar cannot be specfied in weaken' if ref($_[0]) eq '';
+ return bless \(my $type = $_[0]), JSON_TYPE_WEAKEN_CLASS;
}
1;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/XS.pm new/Cpanel-JSON-XS-4.06/XS.pm
--- old/Cpanel-JSON-XS-4.04/XS.pm 2018-06-22 19:31:51.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/XS.pm 2018-08-23 09:49:34.000000000 +0200
@@ -1,5 +1,5 @@
package Cpanel::JSON::XS;
-our $VERSION = '4.04';
+our $VERSION = '4.06';
our $XS_VERSION = $VERSION;
# $VERSION = eval $VERSION;
@@ -1499,6 +1499,14 @@
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, i.e. C, or the numbers 0 or 0.0.
+
+true is eq to the string 'true' or to the special string C
+(i.e. C) or to the numbers 1 or 1.0.
+
=item blessed objects
Blessed objects are not directly representable in JSON, but
@@ -2216,16 +2224,22 @@
"--" => 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) = ref ($_[0]) ? ($_[0], $_[1]) : ($_[1], $_[0]);
+ my ($obj, $op) = $_[2] ? ($_[1], $_[0]) : ($_[0], $_[1]);
+ #warn "ne obj:$obj op:$op";
return !($obj eq $op);
},
fallback => 1);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/XS.xs new/Cpanel-JSON-XS-4.06/XS.xs
--- old/Cpanel-JSON-XS-4.04/XS.xs 2018-06-21 16:33:55.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/XS.xs 2018-08-19 18:54:16.000000000 +0200
@@ -231,6 +231,9 @@
/* flags */
#define JSON_TYPE_CAN_BE_NULL 0x0100
+/* null type */
+#define JSON_TYPE_NULL JSON_TYPE_CAN_BE_NULL
+
/* classes */
#define JSON_TYPE_CLASS "Cpanel::JSON::XS::Type"
#define JSON_TYPE_ARRAYOF_CLASS "Cpanel::JSON::XS::Type::ArrayOf"
@@ -2190,7 +2193,7 @@
#define DEC_INC_DEPTH if (++dec->depth > dec->json.max_depth) ERR (ERR_NESTING_EXCEEDED)
#define DEC_DEC_DEPTH --dec->depth
-static SV *decode_sv (pTHX_ dec_t *dec);
+static SV *decode_sv (pTHX_ dec_t *dec, SV *typesv);
/* #regen code
my $i;
@@ -3008,7 +3011,7 @@
}
static SV *
-decode_num (pTHX_ dec_t *dec)
+decode_num (pTHX_ dec_t *dec, SV *typesv)
{
int is_nv = 0;
char *start = dec->cur;
@@ -3073,6 +3076,9 @@
{
int len = dec->cur - start;
+ if (typesv)
+ sv_setiv_mg (typesv, JSON_TYPE_INT);
+
/* special case the rather common 1..5-digit-int case */
if (*start == '-')
switch (len)
@@ -3136,6 +3142,9 @@
return newSVpvn (start, dec->cur - start);
}
+ if (typesv)
+ sv_setiv_mg (typesv, JSON_TYPE_FLOAT);
+
if (dec->json.flags & F_ALLOW_BIGNUM) {
SV* pv = newSVpvs("require Math::BigFloat && return Math::BigFloat->new(\"");
sv_catpvn(pv, start, dec->cur - start);
@@ -3158,21 +3167,37 @@
}
static SV *
-decode_av (pTHX_ dec_t *dec)
+decode_av (pTHX_ dec_t *dec, SV *typesv)
{
AV *av = newAV ();
+ AV *typeav = NULL;
+ SV *typerv;
DEC_INC_DEPTH;
decode_ws (dec);
+ if (typesv)
+ {
+ typeav = newAV ();
+ typerv = newRV_noinc ((SV *)typeav);
+ SvSetMagicSV (typesv, typerv);
+ }
+
if (*dec->cur == ']')
++dec->cur;
else
for (;;)
{
SV *value;
+ SV *value_typesv = NULL;
+
+ if (typesv)
+ {
+ value_typesv = newSV (0);
+ av_push (typeav, value_typesv);
+ }
- value = decode_sv (aTHX_ dec);
+ value = decode_sv (aTHX_ dec, value_typesv);
if (!value)
goto fail;
@@ -3210,10 +3235,12 @@
}
static SV *
-decode_hv (pTHX_ dec_t *dec)
+decode_hv (pTHX_ dec_t *dec, SV *typesv)
{
SV *sv;
HV *hv = newHV ();
+ HV *typehv = NULL;
+ SV *typerv;
int allow_squote = dec->json.flags & F_ALLOW_SQUOTE;
int allow_barekey = dec->json.flags & F_ALLOW_BAREKEY;
int relaxed = dec->json.flags & F_RELAXED;
@@ -3222,6 +3249,13 @@
DEC_INC_DEPTH;
decode_ws (dec);
+ if (typesv)
+ {
+ typehv = newHV ();
+ typerv = newRV_noinc ((SV *)typehv);
+ SvSetMagicSV (typesv, typerv);
+ }
+
if (*dec->cur == '}')
++dec->cur;
else
@@ -3252,6 +3286,7 @@
/* the overhead of decode_str + hv_store_ent. */
{
SV *value;
+ SV *value_typesv = NULL;
char *p = dec->cur;
char *e = p + 24; /* only try up to 24 bytes */
@@ -3271,7 +3306,14 @@
decode_ws (dec); EXPECT_CH (':');
decode_ws (dec);
- value = decode_sv (aTHX_ dec);
+
+ if (typesv)
+ {
+ value_typesv = newSV (0);
+ hv_store_ent (typehv, key, value_typesv, 0);
+ }
+
+ value = decode_sv (aTHX_ dec, value_typesv);
if (!value)
{
SvREFCNT_dec (key);
@@ -3307,7 +3349,14 @@
decode_ws (dec); if (*p != ':') EXPECT_CH (':');
decode_ws (dec);
- value = decode_sv (aTHX_ dec);
+
+ if (typesv)
+ {
+ value_typesv = newSV (0);
+ hv_store (typehv, key, len, value_typesv, 0);
+ }
+
+ value = decode_sv (aTHX_ dec, value_typesv);
if (!value)
goto fail;
@@ -3434,7 +3483,7 @@
decode_ws (dec);
- tag = decode_sv (aTHX_ dec);
+ tag = decode_sv (aTHX_ dec, NULL);
if (!tag)
goto fail;
@@ -3450,7 +3499,7 @@
decode_ws (dec);
- val = decode_sv (aTHX_ dec);
+ val = decode_sv (aTHX_ dec, NULL);
if (!val)
goto fail;
@@ -3505,33 +3554,42 @@
}
static SV *
-decode_sv (pTHX_ dec_t *dec)
+decode_sv (pTHX_ dec_t *dec, SV *typesv)
{
/* the beauty of JSON: you need exactly one character lookahead */
/* to parse everything. */
switch (*dec->cur)
{
- case '"': ++dec->cur; return decode_str (aTHX_ dec);
+ case '"':
+ ++dec->cur;
+ if (typesv)
+ sv_setiv_mg (typesv, JSON_TYPE_STRING);
+ return decode_str (aTHX_ dec);
case 0x27:
if (dec->json.flags & F_ALLOW_SQUOTE) {
- ++dec->cur; return decode_str_sq (aTHX_ dec);
+ ++dec->cur;
+ if (typesv)
+ sv_setiv_mg (typesv, JSON_TYPE_STRING);
+ return decode_str_sq (aTHX_ dec);
}
ERR ("malformed JSON string, neither tag, array, object, number, string or atom");
break;
- case '[': ++dec->cur; return decode_av (aTHX_ dec);
- case '{': ++dec->cur; return decode_hv (aTHX_ dec);
+ case '[': ++dec->cur; return decode_av (aTHX_ dec, typesv);
+ case '{': ++dec->cur; return decode_hv (aTHX_ dec, typesv);
case '(': return decode_tag (aTHX_ dec);
case '-':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
- return decode_num (aTHX_ dec);
+ return decode_num (aTHX_ dec, typesv);
case 't':
if (dec->end - dec->cur >= 4 && memEQc(dec->cur, "true"))
{
dMY_CXT;
dec->cur += 4;
+ if (typesv)
+ sv_setiv_mg (typesv, JSON_TYPE_BOOL);
return newSVsv(MY_CXT.json_true);
}
else
@@ -3544,6 +3602,8 @@
{
dMY_CXT;
dec->cur += 5;
+ if (typesv)
+ sv_setiv_mg (typesv, JSON_TYPE_BOOL);
return newSVsv(MY_CXT.json_false);
}
else
@@ -3555,6 +3615,8 @@
if (dec->end - dec->cur >= 4 && memEQc(dec->cur, "null"))
{
dec->cur += 4;
+ if (typesv)
+ sv_setiv_mg (typesv, JSON_TYPE_NULL);
return newSVsv(&PL_sv_undef);
}
else
@@ -3620,7 +3682,7 @@
}
static SV *
-decode_json (pTHX_ SV *string, JSON *json, STRLEN *offset_return)
+decode_json (pTHX_ SV *string, JSON *json, STRLEN *offset_return, SV *typesv)
{
dec_t dec;
SV *sv;
@@ -3724,7 +3786,7 @@
*dec.end = 0; /* this should basically be a nop, too, but make sure it's there */
decode_ws (&dec);
- sv = decode_sv (aTHX_ &dec);
+ sv = decode_sv (aTHX_ &dec, typesv);
if (offset_return) {
if (dec.cur < SvPVX (string) || dec.cur > SvEND (string))
@@ -3956,6 +4018,7 @@
newCONSTSUB(stash, "JSON_TYPE_INT", newSViv(JSON_TYPE_INT));
newCONSTSUB(stash, "JSON_TYPE_FLOAT", newSViv(JSON_TYPE_FLOAT));
newCONSTSUB(stash, "JSON_TYPE_STRING", newSViv(JSON_TYPE_STRING));
+ newCONSTSUB(stash, "JSON_TYPE_NULL", newSViv(JSON_TYPE_NULL));
newCONSTSUB(stash, "JSON_TYPE_INT_OR_NULL", newSViv(JSON_TYPE_INT | JSON_TYPE_CAN_BE_NULL));
newCONSTSUB(stash, "JSON_TYPE_BOOL_OR_NULL", newSViv(JSON_TYPE_BOOL | JSON_TYPE_CAN_BE_NULL));
newCONSTSUB(stash, "JSON_TYPE_FLOAT_OR_NULL", newSViv(JSON_TYPE_FLOAT | JSON_TYPE_CAN_BE_NULL));
@@ -4161,17 +4224,17 @@
PUTBACK; scalar = encode_json (aTHX_ scalar, self, typesv); SPAGAIN;
XPUSHs (scalar);
-void decode (JSON *self, SV *jsonstr)
+void decode (JSON *self, SV *jsonstr, SV *typesv = NULL)
PPCODE:
- PUTBACK; jsonstr = decode_json (aTHX_ jsonstr, self, 0); SPAGAIN;
+ PUTBACK; jsonstr = decode_json (aTHX_ jsonstr, self, 0, typesv); SPAGAIN;
XPUSHs (jsonstr);
-void decode_prefix (JSON *self, SV *jsonstr)
+void decode_prefix (JSON *self, SV *jsonstr, SV *typesv = NULL)
PPCODE:
{
SV *sv;
STRLEN offset;
- PUTBACK; sv = decode_json (aTHX_ jsonstr, self, &offset); SPAGAIN;
+ PUTBACK; sv = decode_json (aTHX_ jsonstr, self, &offset, typesv); SPAGAIN;
EXTEND (SP, 2);
PUSHs (sv);
PUSHs (sv_2mortal (newSVuv (ptr_to_index (aTHX_ jsonstr, offset))));
@@ -4257,7 +4320,7 @@
}
}
- PUTBACK; sv = decode_json (aTHX_ self->incr_text, self, &offset); SPAGAIN;
+ PUTBACK; sv = decode_json (aTHX_ self->incr_text, self, &offset, NULL); SPAGAIN;
XPUSHs (sv);
endp = SvPVX(self->incr_text) + offset;
@@ -4346,7 +4409,7 @@
XPUSHs (scalar);
}
-void decode_json (SV *jsonstr, SV *allow_nonref = NULL)
+void decode_json (SV *jsonstr, SV *allow_nonref = NULL, SV *typesv = NULL)
ALIAS:
_from_json = 0
decode_json = F_UTF8
@@ -4357,7 +4420,7 @@
json.flags |= ix;
if (ix && allow_nonref)
json.flags |= F_ALLOW_NONREF;
- PUTBACK; jsonstr = decode_json (aTHX_ jsonstr, &json, 0); SPAGAIN;
+ PUTBACK; jsonstr = decode_json (aTHX_ jsonstr, &json, 0, typesv); SPAGAIN;
XPUSHs (jsonstr);
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/t/113_overloaded_eq.t new/Cpanel-JSON-XS-4.06/t/113_overloaded_eq.t
--- old/Cpanel-JSON-XS-4.04/t/113_overloaded_eq.t 2015-11-30 17:17:08.000000000 +0100
+++ new/Cpanel-JSON-XS-4.06/t/113_overloaded_eq.t 2018-08-23 09:49:34.000000000 +0200
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use strict;
-use Test::More tests => 4;
+use Test::More tests => 15;
use Cpanel::JSON::XS;
@@ -20,6 +20,18 @@
eval q{ $json->encode( $bar ) };
ok(!$@);
+# GH#116, GH#117
+ok(Cpanel::JSON::XS::false eq "", 'false eq ""');
+ok(Cpanel::JSON::XS::false eq 0, 'false eq 0');
+ok(Cpanel::JSON::XS::false eq 0.0, 'false eq 0.0');
+ok(Cpanel::JSON::XS::false eq "false", 'false eq "false"');
+ok(Cpanel::JSON::XS::false eq !!0, 'false eq !!0');
+ok(!(Cpanel::JSON::XS::false eq "true"), 'false ne "true"');
+ok(!(Cpanel::JSON::XS::false eq "string"), 'false ne "string"');
+ok(Cpanel::JSON::XS::true eq "true", 'true eq "true"');
+ok(Cpanel::JSON::XS::true eq 1, 'true eq 1');
+ok(Cpanel::JSON::XS::true eq !0, 'true eq !0');
+ok(Cpanel::JSON::XS::false ne Cpanel::JSON::XS::true, 'false ne true');
package Foo;
@@ -52,11 +64,9 @@
use overload 'eq' => sub { $_[0]->{v} eq $_[1] }, '""' => sub { $_[0]->{v} }, fallback => 1;
-
sub new {
bless { v => $_[1] }, $_[0];
}
-
sub TO_JSON { "$_[0]"; }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Cpanel-JSON-XS-4.04/t/118_type.t new/Cpanel-JSON-XS-4.06/t/118_type.t
--- old/Cpanel-JSON-XS-4.04/t/118_type.t 2018-06-21 13:18:27.000000000 +0200
+++ new/Cpanel-JSON-XS-4.06/t/118_type.t 2018-08-19 18:54:16.000000000 +0200
@@ -3,13 +3,16 @@
use Cpanel::JSON::XS;
use Cpanel::JSON::XS::Type;
+
+my $have_weaken;
BEGIN {
- if ($] < 5.014) {
- use Test::More skip_all => 'This test requires 5.14 - stacked labels';
- }
+ if (eval { require Scalar::Util }) {
+ Scalar::Util->import('weaken');
+ $have_weaken = 1;
+ }
}
-use Test::More tests => 244;
+use Test::More tests => 247;
my $cjson = Cpanel::JSON::XS->new->canonical->allow_nonref;
@@ -196,8 +199,7 @@
SKIP: {
- skip "no Scalar::Util in $]", 2 if $] < 5.007;
- require Scalar::Util;
+ skip "no Scalar::Util in $]", 2 unless $have_weaken;
my $weakref;
{
my $perl_struct = { key1 => 'string', key2 => '10',
@@ -205,37 +207,35 @@
key3 => { key1 => 'level2', key2 => 30 } } };
my $type_spec = { key1 => JSON_TYPE_STRING, key2 => JSON_TYPE_INT };
$type_spec->{key3} = $type_spec;
- Scalar::Util::weaken($type_spec->{key3});
+ weaken($type_spec->{key3});
my $json_string = $cjson->encode($perl_struct, $type_spec);
is($json_string, '{"key1":"string","key2":10,"key3":'
.'{"key1":"level1","key2":20,"key3":{"key1":"level2","key2":30}}}');
$weakref = $type_spec;
- Scalar::Util::weaken($weakref);
+ weaken($weakref);
}
ok(not defined $weakref);
}
SKIP: {
- skip "no Scalar::Util in $]", 2 if $] < 5.007;
- require Scalar::Util;
+ skip "no Scalar::Util in $]", 2 unless $have_weaken;
my $weakref;
{
my $perl_struct = [ "10", 10.2, undef, 10, [ [ "10", 10 ], 10.3, undef ], 10 ];
my $type_arrayof = json_type_arrayof(my $type_spec);
$type_spec = json_type_anyof(JSON_TYPE_INT_OR_NULL, $type_arrayof);
${$type_arrayof} = $type_spec;
- Scalar::Util::weaken(${$type_arrayof});
+ weaken(${$type_arrayof});
my $json_string = $cjson->encode($perl_struct, $type_spec);
is($json_string, '[10,10,null,10,[[10,10],10,null],10]');
$weakref = $type_spec;
- Scalar::Util::weaken($weakref);
+ weaken($weakref);
}
ok(not defined $weakref);
}
SKIP: {
- skip "no Scalar::Util in $]", 2 if $] < 5.007;
- require Scalar::Util;
+ skip "no Scalar::Util in $]", 2 unless $have_weaken;
my $weakref;
{
my $perl_struct = { type => "TYPE", value => "VALUE",
@@ -246,14 +246,14 @@
my $type_spec = { type => JSON_TYPE_STRING, value => 0,
position => { line => JSON_TYPE_INT, column => JSON_TYPE_INT } };
my $type_spec_content = json_type_arrayof($type_spec);
- Scalar::Util::weaken(${$type_spec_content});
+ weaken(${$type_spec_content});
$type_spec->{content} = $type_spec_content;
my $json_string = $cjson->encode($perl_struct, $type_spec);
is ($json_string,
'{"content":[{"position":{"column":13,"line":12},"type":"TYPE2","value":"VALUE2"}],'.
'"position":{"column":11,"line":10},"type":"TYPE","value":"VALUE"}');
$weakref = $type_spec;
- Scalar::Util::weaken($weakref);
+ weaken($weakref);
}
ok(not defined $weakref);
}
@@ -290,3 +290,33 @@
ok(!defined eval { json_type_hashof(JSON_TYPE_STRING, JSON_TYPE_INT) });
like($@, qr/Exactly one type must be specified in hashof/);
+
+SKIP: {
+ skip "no Scalar::Util in $]", 1 unless $have_weaken;
+ my $struct = {};
+ $struct->{recursive} = json_type_arrayof(json_type_weaken($struct));
+ my $weakref = $struct->{recursive};
+ weaken($weakref);
+ undef $struct;
+ ok(!defined $weakref);
+}
+
+SKIP: {
+ skip "no Scalar::Util in $]", 1 unless $have_weaken;
+ my $struct = {};
+ $struct->{recursive} = json_type_hashof(json_type_weaken($struct));
+ my $weakref = $struct->{recursive};
+ weaken($weakref);
+ undef $struct;
+ ok(!defined $weakref);
+}
+
+SKIP: {
+ skip "no Scalar::Util in $]", 1 unless $have_weaken;
+ my $struct = {};
+ $struct->{recursive} = json_type_anyof(json_type_weaken($struct));
+ my $weakref = $struct->{recursive};
+ weaken($weakref);
+ undef $struct;
+ ok(!defined $weakref);
+}