Development

Changeset 1437

You must first sign up to be able to contribute.

Changeset 1437

Show
Ignore:
Timestamp:
06/13/06 14:33:45 (2 years ago)
Author:
fabien
Message:
  • Added 'strict' option, with a more rigid regex. (Fixes ticket #462)
  • Note: 'strict' option is marked true by default (backward compatibility issue)

(closes #462 - patch from slickrick)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/validator/sfEmailValidator.class.php

    r1415 r1437  
    3232  public function execute (&$value, &$error) 
    3333  { 
    34     /* Cal Henderson: http://iamcal.com/publish/articles/php/parsing_email/pdf/ 
    35      * The long regular expression below is made by the following code 
    36      * fragment: 
    37      * 
    38      *   $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; 
    39      *   $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; 
    40      *   $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c' 
    41      *         . '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; 
    42      *   $quoted_pair = '\\x5c\\x00-\\x7f'; 
    43      *   $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d"; 
    44      *   $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22"; 
    45      *   $domain_ref = $atom; 
    46      *   $sub_domain = "($domain_ref|$domain_literal)"; 
    47      *   $word = "($atom|$quoted_string)"; 
    48      *   $domain = "$sub_domain(\\x2e$sub_domain)*"; 
    49      *   $local_part = "$word(\\x2e$word)*"; 
    50      *   $addr_spec = "$local_part\\x40$domain"; 
    51      */ 
    52     $re = '/^([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-' 
    53          .'\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22\\x5c\\x80-\\xff]|\\x5c\\x00-' 
    54          .'\\x7f)*\\x22)(\\x2e([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' 
    55          .'\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22\\x5c\\x80' 
    56          .'-\\xff]|\\x5c\\x00-\\x7f)*\\x22))*\\x40([^\\x00-\\x20\\x22\\x28\\x29' 
    57          .'\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x5b([^' 
    58          .'\\x0d\\x5b-\\x5d\\x80-\\xff]|\\x5c\\x00-\\x7f)*\\x5d)(\\x2e([^\\x00-' 
    59          .'\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-' 
    60          .'\\xff]+|\\x5b([^\\x0d\\x5b-\\x5d\\x80-\\xff]|\\x5c\\x00-\\x7f)*' 
    61          .'\\x5d))*$/' 
    62     ; 
     34    $strict = $this->getParameterHolder()->get('strict'); 
     35    if ($strict == true) 
     36    { 
     37      $re = '/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i'; 
     38    } 
     39    else 
     40    { 
     41      /* Cal Henderson: http://iamcal.com/publish/articles/php/parsing_email/pdf/ 
     42       * The long regular expression below is made by the following code 
     43       * fragment: 
     44       * 
     45       *   $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; 
     46       *   $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; 
     47       *   $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c' 
     48       *         . '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; 
     49       *   $quoted_pair = '\\x5c\\x00-\\x7f'; 
     50       *   $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d"; 
     51       *   $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22"; 
     52       *   $domain_ref = $atom; 
     53       *   $sub_domain = "($domain_ref|$domain_literal)"; 
     54       *   $word = "($atom|$quoted_string)"; 
     55       *   $domain = "$sub_domain(\\x2e$sub_domain)*"; 
     56       *   $local_part = "$word(\\x2e$word)*"; 
     57       *   $addr_spec = "$local_part\\x40$domain"; 
     58       */ 
     59 
     60      $re = '/^([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-' 
     61           .'\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22\\x5c\\x80-\\xff]|\\x5c\\x00-' 
     62           .'\\x7f)*\\x22)(\\x2e([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' 
     63           .'\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22\\x5c\\x80' 
     64           .'-\\xff]|\\x5c\\x00-\\x7f)*\\x22))*\\x40([^\\x00-\\x20\\x22\\x28\\x29' 
     65           .'\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x5b([^' 
     66           .'\\x0d\\x5b-\\x5d\\x80-\\xff]|\\x5c\\x00-\\x7f)*\\x5d)(\\x2e([^\\x00-' 
     67           .'\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-' 
     68           .'\\xff]+|\\x5b([^\\x0d\\x5b-\\x5d\\x80-\\xff]|\\x5c\\x00-\\x7f)*' 
     69           .'\\x5d))*$/' 
     70      ; 
     71    } 
    6372 
    6473    if (!preg_match($re, $value)) 
     
    7786 
    7887    // set defaults 
     88    $this->getParameterHolder()->set('strict',      true); 
    7989    $this->getParameterHolder()->set('email_error', 'Invalid input'); 
    8090