Skip to content
Snippets Groups Projects
Commit 3dde0041 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

externalize regexps in dedicated package

parent 9e7fe9cc
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ use AccountManager::Data::DB;
use AccountManager::Data::Entity;
use AccountManager::Data::Token;
use AccountManager::L10N;
use AccountManager::Regexp;
sub init_l10n {
my $self = shift;
......@@ -146,20 +147,10 @@ sub get_sp {
user_message => "missing_entityid"
) if !$entityid;
my $pattern = qr{
^
(?:
https?://[\w.:/-]+
|
urn:[\w.:-]+
)
$
}x;
return $self->abort(
log_message => "Invalid parameter: entityid",
user_message => "invalid_entityid"
) if $entityid !~ $pattern;
) if $entityid !~ $AccountManager::Regexp::entityid;
my $db = $self->stash('db');
......
......@@ -10,6 +10,7 @@ use Syntax::Keyword::Try;
use Template::Constants qw(:chomp);
use AccountManager::Data::Token;
use AccountManager::Regexp;
use AccountManager::Tools;
sub run {
......@@ -43,7 +44,7 @@ sub run {
return $self->abort(
log_message => "Invalid parameter: email",
user_message => "invalid_email"
) if $email !~ /^ [\w\-.+]+ @ [\w\-.+]+ $/x;
) if $email !~ $AccountManager::Regexp::email;
# override metadata contacts if needed
$self->mock_contacts($sp);
......
package AccountManager::Regexp;
use Mojo::Base -base;
our $email = qr/
^
[\w\-.+=]+
@
(?:[\w-]+\.)+ # at least one name component
[a-zA-Z]{1,63} # one mandatory tld
$
/x;
our $entityid = qr/
^
(?:
https?:\/\/[\w.:\/-]+
|
urn:[\w.:-]+
)
$
/x;
1;
......@@ -7,6 +7,7 @@ nobase_applib_DATA = \
AccountManager/Data/Object.pm \
AccountManager/Data/Token.pm \
AccountManager/Metadata.pm \
AccountManager/Regexp.pm \
AccountManager/Tools.pm \
AccountManager/L10N.pm \
AccountManager/L10N/en.pm \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment