Commit 91f179ec authored by sikeda's avatar sikeda
Browse files

[-feature] Separating collection of regexps in tools.pm as a new module Sympa::Regexps.

"Sympa::Regexps::<type>" would be used instead of (a bit slower) "tools::get_regexp(type)".


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@10660 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 4bd6b3f3
......@@ -55,6 +55,7 @@ nobase_modules_DATA = \
Marc/Search.pm \
Message.pm \
PlainDigest.pm \
Sympa/Regexps.pm \
report.pm \
Robot.pm \
Scenario.pm \
......
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$
# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014 GIP RENATER
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
package Sympa::Regexps;
use strict;
use warnings;
no warnings 'ambiguous';
## Regexps for list params
## Caution : if this regexp changes (more/less parenthesis), then regexp using
## it should also be changed
use constant email => '([\w\-\_\.\/\+\=\'\&]+|\".*\")\@[\w\-]+(\.[\w\-]+)+';
use constant family_name => '[a-z0-9][a-z0-9\-\.\+_]*';
use constant template_name => '[a-zA-Z0-9][a-zA-Z0-9\-\.\+_\s]*'; ## Allow \s
use constant host => '[\w\.\-]+';
use constant multiple_host_with_port =>
'[\w\.\-]+(:\d+)?(,[\w\.\-]+(:\d+)?)*';
use constant listname => '[a-z0-9][a-z0-9\-\.\+_]{0,49}';
use constant sql_query => '(SELECT|select).*';
use constant scenario => '[\w,\.\-]+';
use constant task => '\w+';
use constant datasource => '[\w-]+';
use constant uid => '[\w\-\.\+]+';
use constant time => '[012]?[0-9](?:\:[0-5][0-9])?';
use constant time_range => __PACKAGE__->time . '-' . __PACKAGE__->time;
use constant time_ranges => time_range() . '(?:\s+' . time_range() . ')*';
use constant re =>
'(?i)(?:AW|(?:\xD0\x9D|\xD0\xBD)(?:\xD0\x90|\xD0\xB0)|Re(?:\^\d+|\*\d+|\*\*\d+|\[\d+\])?|Rif|SV|VS|Antw|\xCE\x91(?:\xCE\xA0|\xCF\x80)|\xCE\xA3(?:\xCE\xA7\xCE\x95\xCE\xA4|\xCF\x87\xCE\xB5\xCF\x84)|Odp|YNT)\s*:';
# (de | ru etc. | en, la etc. | it | da, sv | fi | nl | el | el | pl | tr).
1;
......@@ -46,11 +46,12 @@ use if (5.008 < $] && $] < 5.016), qw(Unicode::CaseFold fc);
use if (5.016 <= $]), qw(feature fc);
use Conf;
use Sympa::Constants;
use Sympa::Language;
use Sympa::LockedFile;
use Log;
use Sympa::Constants;
use Message;
use Sympa::Regexps;
use SDM;
## RCS identification.
......@@ -61,29 +62,6 @@ my $cipher;
my $separator="------- CUT --- CUT --- CUT --- CUT --- CUT --- CUT --- CUT -------";
## Regexps for list params
## Caution : if this regexp changes (more/less parenthesis), then regexp using it should
## also be changed
my $time_regexp = '[012]?[0-9](?:\:[0-5][0-9])?';
my $time_range_regexp = $time_regexp.'-'.$time_regexp;
my %regexp = ('email' => '([\w\-\_\.\/\+\=\'\&]+|\".*\")\@[\w\-]+(\.[\w\-]+)+',
'family_name' => '[a-z0-9][a-z0-9\-\.\+_]*',
'template_name' => '[a-zA-Z0-9][a-zA-Z0-9\-\.\+_\s]*', ## Allow \s
'host' => '[\w\.\-]+',
'multiple_host_with_port' => '[\w\.\-]+(:\d+)?(,[\w\.\-]+(:\d+)?)*',
'listname' => '[a-z0-9][a-z0-9\-\.\+_]{0,49}',
'sql_query' => '(SELECT|select).*',
'scenario' => '[\w,\.\-]+',
'task' => '\w+',
'datasource' => '[\w-]+',
'uid' => '[\w\-\.\+]+',
'time' => $time_regexp,
'time_range' => $time_range_regexp,
'time_ranges' => $time_range_regexp.'(?:\s+'.$time_range_regexp.')*',
're' => '(?i)(?:AW|(?:\xD0\x9D|\xD0\xBD)(?:\xD0\x90|\xD0\xB0)|Re(?:\^\d+|\*\d+|\*\*\d+|\[\d+\])?|Rif|SV|VS|Antw|\xCE\x91(?:\xCE\xA0|\xCF\x80)|\xCE\xA3(?:\xCE\xA7\xCE\x95\xCE\xA4|\xCF\x87\xCE\xB5\xCF\x84)|Odp|YNT)\s*:',
# ( de | ru etc. | en, la etc. | it | da, sv | fi | nl | el | el | pl | tr ).
);
my %openssl_errors = (1 => 'an error occurred parsing the command options',
2 => 'one of the input files could not be read',
3 => 'an error occurred creating the PKCS#7 file or when reading the MIME message',
......@@ -2844,7 +2822,8 @@ sub get_dir_size {
sub valid_email {
my $email = shift;
unless ($email =~ /^$regexp{'email'}$/) {
my $email_re = Sympa::Regexps::email();
unless ($email =~ /^${email_re}$/) {
&Log::do_log('err', "Invalid email address '%s'", $email);
return undef;
}
......@@ -3710,8 +3689,8 @@ sub get_separator {
sub get_regexp {
my $type = shift;
if (defined $regexp{$type}) {
return $regexp{$type};
if (my $re = Sympa::Regexps->can($type)) {
return $re->();
}else {
return '\w+'; ## default is a very strict regexp
}
......
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$
use strict;
use warnings;
use Test::More;
use Sympa::Regexps;
my %tests = (
email => '([\w\-\_\.\/\+\=\'\&]+|\".*\")\@[\w\-]+(\.[\w\-]+)+',
family_name => '[a-z0-9][a-z0-9\-\.\+_]*',
template_name => '[a-zA-Z0-9][a-zA-Z0-9\-\.\+_\s]*',
host => '[\w\.\-]+',
multiple_host_with_port =>
'[\w\.\-]+(:\d+)?(,[\w\.\-]+(:\d+)?)*',
listname => '[a-z0-9][a-z0-9\-\.\+_]{0,49}',
sql_query => '(SELECT|select).*',
scenario => '[\w,\.\-]+',
task => '\w+',
datasource => '[\w-]+',
uid => '[\w\-\.\+]+',
time => '[012]?[0-9](?:\:[0-5][0-9])?',
time_range => '[012]?[0-9](?:\:[0-5][0-9])?-[012]?[0-9](?:\:[0-5][0-9])?',
time_ranges => '[012]?[0-9](?:\:[0-5][0-9])?-[012]?[0-9](?:\:[0-5][0-9])?(?:\s+[012]?[0-9](?:\:[0-5][0-9])?-[012]?[0-9](?:\:[0-5][0-9])?)*',
);
plan tests => scalar keys %tests;
foreach my $type (keys %tests) {
ok(eval("Sympa::Regexps::$type"), $tests{$type});
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment