summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2010-05-16 16:39:23 -0400
committerJason Woodward2010-05-16 16:39:23 -0400
commitbce4be64c2d91547affcecbbcea5b22f308e40b6 (patch)
treee15582ec54ea45babdb0fca3e698d43e8621bf47
parenteb929fc7fec6aefdf0a42224885f3eec10b51861 (diff)
downloadJaos-WebApp-bce4be64c2d91547affcecbbcea5b22f308e40b6.tar.gz
::Plugin::CleanParams logging and more comments
-rw-r--r--lib/Jaos/WebApp/Plugin/CleanParams.pm18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/Jaos/WebApp/Plugin/CleanParams.pm b/lib/Jaos/WebApp/Plugin/CleanParams.pm
index 187dc86..2198e52 100644
--- a/lib/Jaos/WebApp/Plugin/CleanParams.pm
+++ b/lib/Jaos/WebApp/Plugin/CleanParams.pm
@@ -23,23 +23,32 @@ sub register
pre_dispatch => sub {
my ($ctx) = @_;
+ # check parameters if we have them
if (my $params = $ctx->req->parameters) {
-
my @keys = $params->keys;
+
for my $key (@keys) {
my @cleaned;
my $validation = $valid->{$key};
+ # if we have a rule for this parameter and are not discarding unkown
if ($validation || !$discard_unknown) {
my @values = $params->get_all($key);
+ # validate each value for the param
for my $value (@values) {
+ # verify validation
if ($validation) {
- $app->log->debug("validationg $key = $value against $validation");
if (ref $validation eq 'Regexp') {
- next unless $value =~ $validation;
+ unless ($value =~ $validation) {
+ $app->log->error("discarding $key as $value != $validation");
+ next;
+ }
} else {
- next unless $value eq $validation;
+ unless ($value eq $validation) {
+ $app->log->error("discarding $key as $value != $validation");
+ next;
+ }
}
}
push @cleaned, encode_html($value);
@@ -49,6 +58,7 @@ sub register
$app->log->error("discarding unknown parameter: $key");
}
+ # reset param with any validated values
$params->remove($key);
$params->add($key, @cleaned) if @cleaned;
}