]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1301884 - Bugzilla needs to use JSON::MaybeXS
authorDylan William Hardison <dylan@hardison.net>
Sat, 10 Sep 2016 16:57:49 +0000 (12:57 -0400)
committerDylan William Hardison <dylan@hardison.net>
Sun, 6 Aug 2017 16:20:12 +0000 (12:20 -0400)
Bugzilla/API/1_0/Util.pm
Bugzilla/API/Server.pm
Bugzilla/Config.pm
Bugzilla/WebService/Server/JSONRPC.pm
Makefile.PL
auth.cgi
xt/lib/QA/REST.pm

index 13c3eebacf60dc6ad90e9904b787682eb084265b..7cd314222f7b91ff24f41e48e17f87c3c6245e01 100644 (file)
@@ -17,7 +17,7 @@ use Bugzilla::Flag;
 use Bugzilla::FlagType;
 use Bugzilla::Util qw(datetime_from email_filter);
 
-use JSON;
+use JSON::MaybeXS;
 use MIME::Base64 qw(decode_base64 encode_base64);
 use Storable qw(dclone);
 use Test::Taint ();
@@ -361,7 +361,7 @@ sub datetime_format_outbound {
 
 # simple types
 
-sub as_boolean  { $_[0] ? JSON::true : JSON::false }
+sub as_boolean  { $_[0] ? JSON->true : JSON->false }
 sub as_double   { defined $_[0] ? $_[0] + 0.0 : JSON::null }
 sub as_int      { defined $_[0] ? int($_[0])  : JSON::null }
 sub as_string   { defined $_[0] ? $_[0] . ''  : JSON::null }
index a423f2f424304eb16ec51c662ffe21ef0e67bc7f..4644b09ac81e756eb836e7bfe9907ded0b39c759 100644 (file)
@@ -18,7 +18,7 @@ use Digest::MD5 qw(md5_base64);
 use File::Spec qw(catfile);
 use HTTP::Request;
 use HTTP::Response;
-use JSON;
+use JSON::MaybeXS;
 use Moo;
 use Module::Runtime qw(require_module);
 use Scalar::Util qw(blessed);
@@ -151,7 +151,7 @@ sub return_error {
     if ($status_code && $message) {
         $self->{_return_error} = {
             status_code => $status_code,
-            error       => JSON::true,
+            error       => JSON->true,
             message     => $message
         };
         $self->{_return_error}->{code} = $error_code if $error_code;
index ae08c503e90486adf7705aceb23040270d88b9f4..f9c5ad08e04cdce67a070f75e73f638a889d549f 100644 (file)
@@ -19,7 +19,7 @@ use Bugzilla::Hook;
 use Bugzilla::Install::Util qw(i_am_persistent);
 use Bugzilla::Util qw(trick_taint read_text write_text);
 
-use JSON::XS;
+use JSON::MaybeXS;
 use File::Temp;
 use File::Basename;
 
@@ -56,7 +56,7 @@ sub _load_params {
     }
     # This hook is also called in editparams.cgi. This call here is required
     # to make SetParam work.
-    Bugzilla::Hook::process('config_modify_panels', 
+    Bugzilla::Hook::process('config_modify_panels',
                             { panels => \%hook_panels });
 
     foreach my $panel (keys %hook_panels) {
@@ -78,7 +78,7 @@ sub param_panels {
         $param_panels->{$module} = "Bugzilla::Config::$module" unless $module eq 'Common';
     }
     # Now check for any hooked params
-    Bugzilla::Hook::process('config_add_panels', 
+    Bugzilla::Hook::process('config_add_panels',
                             { panel_modules => $param_panels });
     return $param_panels;
 }
@@ -175,16 +175,16 @@ sub update_params {
     }
 
     # set verify method to whatever loginmethod was
-    if (exists $param->{'loginmethod'} 
-        && !exists $param->{'user_verify_class'}) 
+    if (exists $param->{'loginmethod'}
+        && !exists $param->{'user_verify_class'})
     {
         $new_params{'user_verify_class'} = $param->{'loginmethod'};
     }
 
     # Remove quip-display control from parameters
     # and give it to users via User Settings (Bug 41972)
-    if ( exists $param->{'enablequips'} 
-         && !exists $param->{'quip_list_entry_control'}) 
+    if ( exists $param->{'enablequips'}
+         && !exists $param->{'quip_list_entry_control'})
     {
         my $new_value;
         ($param->{'enablequips'} eq 'on')       && do {$new_value = 'open';};
@@ -295,9 +295,8 @@ sub write_params {
     $param_data ||= Bugzilla->params;
     my $param_file = bz_locations()->{'datadir'} . '/params.json';
 
-    my $json_data = JSON::XS->new->canonical->pretty->encode($param_data);
+    my $json_data = JSON()->new->canonical->pretty->encode($param_data);
     write_text($param_file, $json_data);
-
     # It's not common to edit parameters and loading
     # Bugzilla::Install::Filesystem is slow.
     require Bugzilla::Install::Filesystem;
@@ -317,9 +316,9 @@ sub read_param_file {
         trick_taint($data);
 
         # If params.json has been manually edited and e.g. some quotes are
-        # missing, we don't want JSON::XS to leak the content of the file
+        # missing, we don't want JSON::MaybeXS to leak the content of the file
         # to all users in its error message, so we have to eval'uate it.
-        $params = eval { JSON::XS->new->decode($data) };
+        $params = eval { JSON()->new->decode($data) };
         if ($@) {
             my $error_msg = (basename($0) eq 'checksetup.pl') ?
                 $@ : 'run checksetup.pl to see the details.';
index b488c8de5fc28f7adde593723fda5357c8b15386..322c4845c451ea3e69fe41384dda752d668b691c 100644 (file)
@@ -166,8 +166,8 @@ sub retrieve_json_from_get {
     my $params;
     if (defined $cgi->param('params')) {
         local $@;
-        $params = eval { 
-            $self->json->decode(scalar $cgi->param('params')) 
+        $params = eval {
+            $self->json->decode(scalar $cgi->param('params'))
         };
         if ($@) {
             ThrowUserError('json_rpc_invalid_params',
@@ -194,12 +194,12 @@ sub retrieve_json_from_get {
 
 sub type {
     my ($self, $type, $value) = @_;
-    
+
     # This is the only type that does something special with undef.
     if ($type eq 'boolean') {
-        return $value ? JSON::true : JSON::false;
+        return $value ? JSON->true : JSON->false;
     }
-    
+
     return JSON::null if !defined $value;
 
     my $retval = $value;
@@ -368,7 +368,7 @@ sub _argument_type_check {
         if (defined $params->{$field}) {
             my $value = $params->{$field};
             if (ref $value eq 'ARRAY') {
-                $params->{$field} = 
+                $params->{$field} =
                     [ map { $self->datetime_format_inbound($_) } @$value ];
             }
             else {
@@ -406,7 +406,7 @@ sub _argument_type_check {
         # methods that can change data. This protects us against cross-site
         # request forgeries.
         if (!grep($_ eq $method, $pkg->READ_ONLY)) {
-            ThrowUserError('json_rpc_post_only', 
+            ThrowUserError('json_rpc_post_only',
                            { method => $self->_bz_method_name });
         }
     }
@@ -420,7 +420,7 @@ sub _argument_type_check {
     $self->handle_login();
 
     # Bugzilla::WebService packages call internal methods like
-    # $self->_some_private_method. So we have to inherit from 
+    # $self->_some_private_method. So we have to inherit from
     # that class as well as this Server class.
     my $new_class = ref($self) . '::' . $pkg;
     my $isa_string = 'our @ISA = qw(' . ref($self) . " $pkg)";
@@ -443,7 +443,7 @@ sub _argument_type_check {
 
 # _bz_method_name is stored by _find_procedure for later use.
 sub _bz_method_name {
-    return $_[0]->{_bz_method_name}; 
+    return $_[0]->{_bz_method_name};
 }
 
 sub _bz_callback {
@@ -510,7 +510,7 @@ L<Bugzilla::WebService/LOGGING IN>.
 
 To connect over GET, simply send the values that you'd normally send for
 each JSON-RPC argument as URL parameters, with the C<params> item being
-a JSON string. 
+a JSON string.
 
 The simplest example is a call to C<Bugzilla.time>:
 
@@ -539,10 +539,10 @@ L<http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/>.
 
 To use JSONP with Bugzilla's JSON-RPC WebService, simply specify a
 C<callback> parameter to jsonrpc.cgi when using it via GET as described above.
-For example, here's some HTML you could use to get the data from 
+For example, here's some HTML you could use to get the data from
 C<Bugzilla.time> on a remote website, using JSONP:
 
- <script type="text/javascript" 
+ <script type="text/javascript"
          src="http://bugzilla.example.com/jsonrpc.cgi?method=Bugzilla.time&amp;callback=foo">
 
 That would call the C<Bugzilla.time> method and pass its value to a function
@@ -599,9 +599,9 @@ throw an error. In Bugzilla, the error contents look like:
 
 So, for example, in JSON-RPC 1.0, an error response would look like:
 
- { 
-   result: null, 
-   error: { message: 'Some message here', code: 123 }, 
+ {
+   result: null,
+   error: { message: 'Some message here', code: 123 },
    id: 1
  }
 
index 7d94b62fa57e933cd73a1d36a6d5fa1c0296680c..c5e8886ee88794f3ce16954747ccf64226dbb7e8 100644 (file)
@@ -48,7 +48,7 @@ my %requires = (
     'Email::Sender'       => '1.300011',
     'HTTP::Request'       => 0,
     'HTTP::Response'      => 0,
-    'JSON::XS'            => '2.01',
+    'JSON::MaybeXS'       => '1.003008',
     'List::MoreUtils'     => '0.32',
     'Math::Random::ISAAC' => '1.0.1',
     'Moo'                 => 2,
index 3f459095358ca0749f58d22095a8727e6f2c801b..862487f72c4c1ab48453aa05f5c6af34082b0cae 100755 (executable)
--- a/auth.cgi
+++ b/auth.cgi
@@ -24,7 +24,7 @@ use URI;
 use URI::QueryParam;
 use Digest::SHA qw(sha256_hex);
 use LWP::UserAgent ();
-use JSON qw(decode_json encode_json);
+use JSON::MaybeXS qw(decode_json encode_json);
 
 Bugzilla->login(LOGIN_REQUIRED);
 
index 23d4f4433d49b367f2bf1e97d062eec9d98a6fc6..463881efb0443f9fea22853071c46503bced6bc6 100644 (file)
@@ -17,7 +17,7 @@ use lib "$RealBin/../../lib", "$RealBin/../../../local/lib/perl5";
 use autodie;
 
 use LWP::UserAgent;
-use JSON;
+use JSON::MaybeXS;
 use QA::Util;
 
 use parent qw(LWP::UserAgent Exporter);