Skip to content
Browse files

changes to email field processing and validation

  • Loading branch information...
2 parents 6fb4ebb + 7bc7810 commit b5fe5b6ceea730eaa0ef57a1c39e9a05415b96c0 @tonycoz committed Feb 26, 2014
View
5 site/cgi-bin/modules/BSE/AdminSiteUsers.pm
@@ -13,7 +13,7 @@ use constant SITEUSER_GROUP_SECT => 'BSE Siteuser groups validation';
use BSE::Template;
use DevHelp::Date qw(dh_parse_date_sql dh_parse_time_sql);
-our $VERSION = "1.013";
+our $VERSION = "1.014";
my %actions =
(
@@ -371,13 +371,15 @@ sub req_save {
my $saveemail;
my $email = $cgi->param('email');
+ $email =~ s/^\s+|\s+$//g;
if (defined $email && $email ne $user->{email} && $email ne '') {
if ($email !~ /.\@./) {
$errors{email} = "Email is invalid";
}
unless ($errors{email}) {
if ($nopassword) {
my $conf_email = $cgi->param('confirmemail');
+ $conf_email =~ s/^\s+|\s+$//g;
if ($conf_email) {
if ($conf_email eq $email) {
my $other = SiteUsers->getBy(userId=>$email);
@@ -643,6 +645,7 @@ sub req_add {
my $nopassword = $cfg->entryBool('site users', 'nopassword', 0);
my %errors;
my $email = $cgi->param('email');
+ $email =~ s/^\s+|\s+$//g;
if (!defined $email) { # required check done later
$email = ''; # prevent undefined value warnings later
}
View
5 site/cgi-bin/modules/BSE/UserReg.pm
@@ -18,7 +18,7 @@ use BSE::Util::Iterate;
use base 'BSE::UI::UserCommon';
use Carp qw(confess);
-our $VERSION = "1.029";
+our $VERSION = "1.030";
use constant MAX_UNACKED_CONF_MSGS => 3;
use constant MIN_UNACKED_CONF_GAP => 2 * 24 * 60 * 60;
@@ -626,6 +626,7 @@ sub req_register {
section => 'site user validation');
my $email = $cgi->param('email');
+ $email =~ s/^\s+|\s+$//g;
if (!defined $email or !length $email) {
$errors{email} = $msgs->(regnoemail => "Please enter an email address");
$email = ''; # prevent undefined value warnings later
@@ -635,6 +636,7 @@ sub req_register {
}
if ($nopassword) {
my $confemail = $cgi->param('confirmemail');
+ $confemail =~ s/^\s+|\s+$//g;
if (!defined $confemail or !length $confemail) {
$errors{confirmemail} = $msgs->(regnoconfemail => "Please enter a confirmation email address");
}
@@ -1122,6 +1124,7 @@ sub req_saveopts {
}
}
my $email = $cgi->param('email');
+ $email =~ s/^\s+|\s+$//g;
my $saveemail;
if (defined $email) {
++$saveemail;
View
4 site/cgi-bin/modules/DevHelp/Validate.pm
@@ -6,7 +6,7 @@ use vars qw(@EXPORT_OK @ISA);
@ISA = qw(Exporter);
use Carp qw(confess);
-our $VERSION = "1.006";
+our $VERSION = "1.007";
my $re_real =
qr/
@@ -25,7 +25,7 @@ my %built_ins =
(
email =>
{
- match => qr/^[^\@]+\@[\w.-]+\.\w+$/,
+ match => qr/^[^\s\@][^\@]*\@[\w.-]+\.\w+$/,
error => '$n is not a valid email address',
},
phone =>
View
20 t/010-modules/020-validate.t
@@ -1,6 +1,6 @@
#!perl -w
use strict;
-use Test::More tests => 82;
+use Test::More tests => 88;
BEGIN { use_ok('DevHelp::Validate'); }
@@ -312,3 +312,21 @@ BEGIN { use_ok('DevHelp::Validate'); }
}
}
}
+
+# emails
+{
+ my $val = DevHelp::Validate::Hash->new
+ (
+ fields =>
+ {
+ email => { rules => "email" },
+ }
+ );
+ my %errors;
+ ok($val->validate({email => 'a@example.com' }, \%errors), 'a@example.com');
+ ok($val->validate({email => 'a+b@example.com' }, \%errors), 'a+b@example.com');
+ ok($val->validate({email => '"a b"@example.com' }, \%errors), '"a b"@example.com');
+ ok(!$val->validate({email => ' a@example.com' }, \%errors), "emails cannot begin with whitespace ");
+ ok(!$val->validate({email => ' a+b@example.com' }, \%errors), "emails cannot begin with whitespace");
+ ok(!$val->validate({email => ' "a b"@example.com' }, \%errors), "emails cannot begin with whitespace");
+}

0 comments on commit b5fe5b6

Please sign in to comment.
Something went wrong with that request. Please try again.