X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=lib%2FCGI%2FEx%2FValidate.pm;fp=lib%2FCGI%2FEx%2FValidate.pm;h=d2717ccdc2fc281aa86b7d7c35c6fe9cb729fd6b;hp=184327b174bad97294c055a69372a0ef578c745a;hb=fdecaac30a1168ed894c46d61b6c95524ec62a4e;hpb=febed4ec71f803b083c3e61b82b9464e9bfb0992 diff --git a/lib/CGI/Ex/Validate.pm b/lib/CGI/Ex/Validate.pm index 184327b..d2717cc 100644 --- a/lib/CGI/Ex/Validate.pm +++ b/lib/CGI/Ex/Validate.pm @@ -8,7 +8,7 @@ package CGI::Ex::Validate; use strict; use Carp qw(croak); -our $VERSION = '2.27'; +our $VERSION = '2.32'; our $QR_EXTRA = qr/^(\w+_error|as_(array|string|hash)_\w+|no_\w+)/; our @UNSUPPORTED_BROWSERS = (qr/MSIE\s+5.0\d/i); our $JS_URI_PATH; @@ -237,16 +237,16 @@ sub validate_buddy { if ($field_val->{'had_error'} && ! $self->{'had_error'}->{$field}) { return [[$field, 'had_error', $field_val, $ifs_match]]; } if ($field_val->{'was_checked'} && ! $self->{'was_checked'}->{$field}) { return [[$field, 'was_checked', $field_val, $ifs_match]]; } - my $values = UNIVERSAL::isa($form->{$field},'ARRAY') ? $form->{$field} : [$form->{$field}]; - my $n_values = @$values; - # allow for default value - if (exists $field_val->{'default'}) { - if ($n_values == 0 || ($n_values == 1 && (! defined($values->[0]) || ! length($values->[0])))) { - $form->{$field} = $values->[0] = $field_val->{'default'}; - } + if (defined($field_val->{'default'}) + && (!defined($form->{$field}) + || (UNIVERSAL::isa($form->{$field},'ARRAY') ? !@{ $form->{$field} } : !length($form->{$field})))) { + $form->{$field} = $field_val->{'default'}; } + my $values = UNIVERSAL::isa($form->{$field},'ARRAY') ? $form->{$field} : [$form->{$field}]; + my $n_values = @$values; + # allow for a few form modifiers my $modified = 0; foreach my $value (@$values) { @@ -564,10 +564,8 @@ sub check_type { # the "username" portion of an email address - sort of arbitrary } elsif ($type eq 'local_part') { return 0 if ! defined($value) || ! length($value); - return 0 if $value =~ m/[^A-Za-z0-9_.\-\^=?\#!&+]/ - || $value =~ m/^[\.\-]/ - || $value =~ m/[\.\-\&]$/ - || $value =~ m/(\.\-|\-\.|\.\.)/; + # ignoring all valid quoted string local parts + return 0 if $value =~ m/[^\w.~!\#\$%\^&*\-=+?]/; # standard IP address } elsif ($type eq 'ip') {