Francois Gouget : testbot/web: Better separate GetParam() and SetParam().
Alexandre Julliard
julliard at winehq.org
Mon Mar 7 15:45:32 CST 2022
Module: tools
Branch: master
Commit: 81cc4388e64e1d0af6a7a57d46fae182e222780e
URL: https://source.winehq.org/git/tools.git/?a=commit;h=81cc4388e64e1d0af6a7a57d46fae182e222780e
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Mon Mar 7 12:47:47 2022 +0100
testbot/web: Better separate GetParam() and SetParam().
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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 b910228..8abaaaa 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 9eba086..ca1ee5e 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 23f57a9..4cfef79 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);
}
More information about the wine-cvs
mailing list