summaryrefslogtreecommitdiffstats
path: root/Bugzilla/WebService/Util.pm
diff options
context:
space:
mode:
authordkl%redhat.com <>2009-01-26 21:40:22 +0100
committerdkl%redhat.com <>2009-01-26 21:40:22 +0100
commitc49af480dcb59aadfa1edb76f246c68917a59765 (patch)
tree86ee9438a99ae209ea0fd8bbc5eddc2376b30b1c /Bugzilla/WebService/Util.pm
parent2319f5f6660df8ed65c44dc29a5b2f42f9d81629 (diff)
downloadbugzilla-c49af480dcb59aadfa1edb76f246c68917a59765.tar.gz
bugzilla-c49af480dcb59aadfa1edb76f246c68917a59765.tar.xz
Bug 473646 - WebService methods should check list parameters for scalars and convert before use
Patch by Dave Lawrence <dkl@redhat.com> - r/a=mkanat
Diffstat (limited to 'Bugzilla/WebService/Util.pm')
-rw-r--r--Bugzilla/WebService/Util.pm28
1 files changed, 27 insertions, 1 deletions
diff --git a/Bugzilla/WebService/Util.pm b/Bugzilla/WebService/Util.pm
index cd75bee8c..74c1f2f02 100644
--- a/Bugzilla/WebService/Util.pm
+++ b/Bugzilla/WebService/Util.pm
@@ -24,7 +24,7 @@ use strict;
use base qw(Exporter);
-our @EXPORT_OK = qw(filter);
+our @EXPORT_OK = qw(filter validate);
sub filter ($$) {
my ($params, $hash) = @_;
@@ -44,6 +44,23 @@ sub filter ($$) {
return \%newhash;
}
+sub validate {
+ my ($self, $params, @keys) = @_;
+
+ # If @keys is not empty then we convert any named
+ # parameters that have scalar values to arrayrefs
+ # that match.
+ foreach my $key (@keys) {
+ if (exists $params->{$key}) {
+ $params->{$key} = ref $params->{$key}
+ ? $params->{$key}
+ : [ $params->{$key} ];
+ }
+ }
+
+ return ($self, $params);
+}
+
__END__
=head1 NAME
@@ -61,6 +78,8 @@ internally in the WebService code.
filter({ include_fields => ['id', 'name'],
exclude_fields => ['name'] }, $hash);
+ validate(@_, 'ids');
+
=head1 METHODS
=over
@@ -72,4 +91,11 @@ of WebService methods. Given a hash (the second argument to this subroutine),
this will remove any keys that are I<not> in C<include_fields> and then remove
any keys that I<are> in C<exclude_fields>.
+=item C<validate>
+
+This helps in the validation of parameters passed into the WebSerice
+methods. Currently it converts listed parameters into an array reference
+if the client only passed a single scalar value. It modifies the parameters
+hash in place so other parameters should be unaltered.
+
=back