From: Dylan William Hardison Date: Sat, 10 Sep 2016 16:57:49 +0000 (-0400) Subject: Bug 1301884 - Bugzilla needs to use JSON::MaybeXS X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c29a091376bb073575e9e42cd779e9d4911a264;p=thirdparty%2Fbugzilla.git Bug 1301884 - Bugzilla needs to use JSON::MaybeXS --- diff --git a/Bugzilla/API/1_0/Util.pm b/Bugzilla/API/1_0/Util.pm index 13c3eebacf..7cd314222f 100644 --- a/Bugzilla/API/1_0/Util.pm +++ b/Bugzilla/API/1_0/Util.pm @@ -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 } diff --git a/Bugzilla/API/Server.pm b/Bugzilla/API/Server.pm index a423f2f424..4644b09ac8 100644 --- a/Bugzilla/API/Server.pm +++ b/Bugzilla/API/Server.pm @@ -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; diff --git a/Bugzilla/Config.pm b/Bugzilla/Config.pm index ae08c503e9..f9c5ad08e0 100644 --- a/Bugzilla/Config.pm +++ b/Bugzilla/Config.pm @@ -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.'; diff --git a/Bugzilla/WebService/Server/JSONRPC.pm b/Bugzilla/WebService/Server/JSONRPC.pm index b488c8de5f..322c4845c4 100644 --- a/Bugzilla/WebService/Server/JSONRPC.pm +++ b/Bugzilla/WebService/Server/JSONRPC.pm @@ -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. To connect over GET, simply send the values that you'd normally send for each JSON-RPC argument as URL parameters, with the C item being -a JSON string. +a JSON string. The simplest example is a call to C: @@ -539,10 +539,10 @@ L. To use JSONP with Bugzilla's JSON-RPC WebService, simply specify a C 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 on a remote website, using JSONP: -