[tools] testbot/web: Better separate GetParam() and SetParam().
Francois Gouget
fgouget at codeweavers.com
Mon Mar 7 05:47:47 CST 2022
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
testbot/lib/ObjectModel/CGI/Page.pm | 39 +++++++++++++++++++++++++----
testbot/web/Feedback.pl | 6 ++---
testbot/web/Register.pl | 4 +--
3 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/testbot/lib/ObjectModel/CGI/Page.pm b/testbot/lib/ObjectModel/CGI/Page.pm
index b91022832c..8abaaaa9d2 100644
--- a/testbot/lib/ObjectModel/CGI/Page.pm
+++ b/testbot/lib/ObjectModel/CGI/Page.pm
@@ -77,18 +77,47 @@ sub GetParamNames($)
=head1 C<GetParam()>
-This thunks to CGI::param() and thus takes the same arguments list but forces
-the result to scalar context to avoid security issues.
+Returns the specified parameter.
+Note that unlike CGI::param() this forces the result to scalar context to
+avoid security issues.
+
To get the list of parameter names use GetParamNames().
=back
=cut
-sub GetParam($@)
+sub GetParam($$)
{
- my $self = shift;
+ my ($self, $Name) = @_;
+
+ return scalar($self->{CGIObj}->param($Name));
+}
+
+=pod
+=over 12
+
+=head1 C<SetParam()>
- return scalar($self->{CGIObj}->param(@_));
+Sets the specified parameter or removes it from the parameters list if the
+value is undefined.
+
+To get the list of parameter names use GetParamNames().
+
+=back
+=cut
+
+sub SetParam($$$)
+{
+ my ($self, $Name, $Value) = @_;
+
+ if (defined $Value)
+ {
+ $self->{CGIObj}->param($Name, $Value);
+ }
+ else
+ {
+ $self->{CGIObj}->delete($Name);
+ }
}
sub CGI($)
diff --git a/testbot/web/Feedback.pl b/testbot/web/Feedback.pl
index 9eba086ace..ca1ee5ed77 100644
--- a/testbot/web/Feedback.pl
+++ b/testbot/web/Feedback.pl
@@ -41,7 +41,7 @@ sub _initialize($$$)
);
if (!$Session and $RegistrationQ)
{
- $self->GetParam("FeedA", "") if (!defined $self->GetParam("FeedA"));
+ $self->SetParam("FeedA", "") if (!defined $self->GetParam("FeedA"));
push @PropertyDescriptors, CreateBasicPropertyDescriptor("FeedA", "Please demonstrate you are not a bot by answering this question: $RegistrationQ", !1, 1, "A", 40);
}
@@ -51,8 +51,8 @@ sub _initialize($$$)
{
# Provide default values
my $User = $Session->User;
- $self->GetParam("Name", $User->RealName) if (!defined $self->GetParam("Name"));
- $self->GetParam("EMail", $User->EMail) if (!defined $self->GetParam("EMail"));
+ $self->SetParam("Name", $User->RealName) if (!defined $self->GetParam("Name"));
+ $self->SetParam("EMail", $User->EMail) if (!defined $self->GetParam("EMail"));
}
}
diff --git a/testbot/web/Register.pl b/testbot/web/Register.pl
index 23f57a9b64..4cfef79fc3 100644
--- a/testbot/web/Register.pl
+++ b/testbot/web/Register.pl
@@ -40,11 +40,11 @@ sub _initialize($$$)
$self->{ExtraProperties} = [];
if ($RegistrationQ)
{
- $self->GetParam("RegA", "") if (!defined $self->GetParam("RegA"));
+ $self->SetParam("RegA", "") if (!defined $self->GetParam("RegA"));
push @{$self->{ExtraProperties}}, CreateBasicPropertyDescriptor("RegA", "Please demonstrate you are not a bot by answering this question: $RegistrationQ", !1, 1, "A", 40);
}
- $self->GetParam("Remarks", "") if (!defined $self->GetParam("Remarks"));
+ $self->SetParam("Remarks", "") if (!defined $self->GetParam("Remarks"));
push @{$self->{ExtraProperties}}, CreateBasicPropertyDescriptor("Remarks", "Remarks", !1, !1, "textarea", 160);
}
--
2.30.2
More information about the wine-devel
mailing list