Bug 1093600: REST shouldn't support multiple instances of parameters for resources which only support a single params (eg. POST bug/comment)
r=glob,a=glob git-svn-id: svn://10.0.0.236/trunk@265668 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
fe358a8183
commit
f39ca8fa32
@ -1 +1 @@
|
|||||||
9203
|
9204
|
||||||
@ -1 +1 @@
|
|||||||
b9543e48f33729c4a4560eac2a856af06ed9e9d5
|
8d368ae66a8839d53978a0e92a6f6ce8c4ab857b
|
||||||
@ -31,6 +31,7 @@ use Bugzilla::WebService::Server::REST::Resources::Product;
|
|||||||
use Bugzilla::WebService::Server::REST::Resources::User;
|
use Bugzilla::WebService::Server::REST::Resources::User;
|
||||||
use Bugzilla::WebService::Server::REST::Resources::BugUserLastVisit;
|
use Bugzilla::WebService::Server::REST::Resources::BugUserLastVisit;
|
||||||
|
|
||||||
|
use List::MoreUtils qw(uniq);
|
||||||
use Scalar::Util qw(blessed reftype);
|
use Scalar::Util qw(blessed reftype);
|
||||||
use MIME::Base64 qw(decode_base64);
|
use MIME::Base64 qw(decode_base64);
|
||||||
|
|
||||||
@ -342,26 +343,29 @@ sub _retrieve_json_params {
|
|||||||
# parameters.
|
# parameters.
|
||||||
if (my $rest_params = $self->bz_rest_params) {
|
if (my $rest_params = $self->bz_rest_params) {
|
||||||
foreach my $param (keys %$rest_params) {
|
foreach my $param (keys %$rest_params) {
|
||||||
if (!exists $params->{$param}) {
|
# If the param does not already exist or if the
|
||||||
|
# rest param is a single value, add it to the
|
||||||
|
# global params.
|
||||||
|
if (!exists $params->{$param} || !ref $rest_params->{$param}) {
|
||||||
$params->{$param} = $rest_params->{$param};
|
$params->{$param} = $rest_params->{$param};
|
||||||
next;
|
|
||||||
}
|
}
|
||||||
my @values = ref $rest_params->{$param}
|
# If rest_param is a list then add any extra values to the list
|
||||||
? @{ $rest_params->{$param} }
|
elsif (ref $rest_params->{$param}) {
|
||||||
: ($rest_params->{$param});
|
my @extra_values = ref $params->{$param}
|
||||||
if (ref $params->{$param}) {
|
? @{ $params->{$param} }
|
||||||
push(@{ $params->{$param} }, @values);
|
: ($params->{$param});
|
||||||
}
|
$params->{$param}
|
||||||
else {
|
= [ uniq (@{ $rest_params->{$param} }, @extra_values) ];
|
||||||
$params->{$param} = [ $params->{$param}, @values ];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Merge any additional query key/values from the request body if non-GET.
|
# Any parameters passed in in the body of a non-GET request will override
|
||||||
# We do this manually cause CGI.pm doesn't understand JSON strings.
|
# any parameters pull from the url path. Otherwise non-unique keys are
|
||||||
|
# combined.
|
||||||
if ($self->request->method ne 'GET') {
|
if ($self->request->method ne 'GET') {
|
||||||
my $extra_params = {};
|
my $extra_params = {};
|
||||||
|
# We do this manually because CGI.pm doesn't understand JSON strings.
|
||||||
my $json = delete $params->{'POSTDATA'} || delete $params->{'PUTDATA'};
|
my $json = delete $params->{'POSTDATA'} || delete $params->{'PUTDATA'};
|
||||||
if ($json) {
|
if ($json) {
|
||||||
eval { $extra_params = $self->json->decode($json); };
|
eval { $extra_params = $self->json->decode($json); };
|
||||||
@ -369,6 +373,14 @@ sub _retrieve_json_params {
|
|||||||
ThrowUserError('json_rpc_invalid_params', { err_msg => $@ });
|
ThrowUserError('json_rpc_invalid_params', { err_msg => $@ });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Allow parameters in the query string if request was non-GET.
|
||||||
|
# Note: parameters in query string body override any matching
|
||||||
|
# parameters in the request body.
|
||||||
|
foreach my $param ($self->cgi->url_param()) {
|
||||||
|
$extra_params->{$param} = $self->cgi->url_param($param);
|
||||||
|
}
|
||||||
|
|
||||||
%{$params} = (%{$params}, %{$extra_params}) if %{$extra_params};
|
%{$params} = (%{$params}, %{$extra_params}) if %{$extra_params};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user