[MOBY-dev] malformed authURI [solved]
Jason Stewart
jason.e.stewart at gmail.com
Sat May 24 11:13:37 UTC 2008
Hey Mark,
2008/5/23 Mark Wilkinson <markw at illuminae.com>:
> the authURI is really intended to be the authority's domain name... so
> whatever regexp/error message changes you think will indicate that please go
> ahead :-)
The regex checking for email and authURI is the same in three
different places so I thought I would centralize it to use a
subroutine that dies on error - so the code can be shared (in case the
messages or the regex's want to get changed later.
The subs look like this:
sub _validateAuthURI {
my $auth = shift @_;
my $error = "";
if ($auth =~ '[/:]') {
$error = "has a colon or a slash - must not have an http:// prefix,
and must not have trailing path info";
} elsif ($auth =~ /\./) {
$error = "must take the form NNN.NNN.NNN";
}
die "Malformed authURI - $error" if $error;
}
sub _validateEmail {
my $email = shift @_;
my $error = "";
if ($email !~ /\S\@\S+\.\S+/) {
$error = "Malformed email - must be a valid email address of the form
name\@organization.foo";
}
die $error if $error;
}
and they replace this code:
return &_error( "Malformed authURI - must not have an http:// prefix", "" )
if $AuthURI =~ '[/:]';
return &_error( "Malformed authURI - must take the form NNN.NNN.NNN", "" )
unless $AuthURI =~ /\./;
return &_error("Malformed email - must be a valid email address of
the form name\@organization.foo","")
unless $contactEmail =~ /\S\@\S+\.\S+/;
with this:
eval {_validateAuthURI($auth)};
&_error($@) if $@;
eval {_validateEmail($email)};
&_error($@) if $@;
Does that look acceptable?
Mark and Eddie, I had one question about using that code in
registerService() - there seems to be two different error handling
strategies going on - there is an $error variable that is being added
to if any payload errors are found, but then authURI and email
validation causes _error() to be called immediately ... I was
wondering if this was accidental or on purpose? Should I changed the
authURI and email validation failure to also add to $error instead of
calling _error() immediately?
Cheers, jas.
More information about the MOBY-dev
mailing list