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
Branches
Tags
No related merge requests found
...@@ -9,6 +9,7 @@ use AccountManager::Data::DB; ...@@ -9,6 +9,7 @@ use AccountManager::Data::DB;
use AccountManager::Data::Entity; use AccountManager::Data::Entity;
use AccountManager::Data::Token; use AccountManager::Data::Token;
use AccountManager::L10N; use AccountManager::L10N;
use AccountManager::Regexp;
sub init_l10n { sub init_l10n {
my $self = shift; my $self = shift;
...@@ -146,20 +147,10 @@ sub get_sp { ...@@ -146,20 +147,10 @@ sub get_sp {
user_message => "missing_entityid" user_message => "missing_entityid"
) if !$entityid; ) if !$entityid;
my $pattern = qr{
^
(?:
https?://[\w.:/-]+
|
urn:[\w.:-]+
)
$
}x;
return $self->abort( return $self->abort(
log_message => "Invalid parameter: entityid", log_message => "Invalid parameter: entityid",
user_message => "invalid_entityid" user_message => "invalid_entityid"
) if $entityid !~ $pattern; ) if $entityid !~ $AccountManager::Regexp::entityid;
my $db = $self->stash('db'); my $db = $self->stash('db');
......
...@@ -10,6 +10,7 @@ use Syntax::Keyword::Try; ...@@ -10,6 +10,7 @@ use Syntax::Keyword::Try;
use Template::Constants qw(:chomp); use Template::Constants qw(:chomp);
use AccountManager::Data::Token; use AccountManager::Data::Token;
use AccountManager::Regexp;
use AccountManager::Tools; use AccountManager::Tools;
sub run { sub run {
...@@ -43,7 +44,7 @@ sub run { ...@@ -43,7 +44,7 @@ sub run {
return $self->abort( return $self->abort(
log_message => "Invalid parameter: email", log_message => "Invalid parameter: email",
user_message => "invalid_email" user_message => "invalid_email"
) if $email !~ /^ [\w\-.+]+ @ [\w\-.+]+ $/x; ) if $email !~ $AccountManager::Regexp::email;
# override metadata contacts if needed # override metadata contacts if needed
$self->mock_contacts($sp); $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 = \ ...@@ -7,6 +7,7 @@ nobase_applib_DATA = \
AccountManager/Data/Object.pm \ AccountManager/Data/Object.pm \
AccountManager/Data/Token.pm \ AccountManager/Data/Token.pm \
AccountManager/Metadata.pm \ AccountManager/Metadata.pm \
AccountManager/Regexp.pm \
AccountManager/Tools.pm \ AccountManager/Tools.pm \
AccountManager/L10N.pm \ AccountManager/L10N.pm \
AccountManager/L10N/en.pm \ AccountManager/L10N/en.pm \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment