• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Email addresses with a "+" are not parsed correctly

#11
[eluser]sophistry[/eluser]
ok, got a few more tweaks here that should be a "final" version.

fixed the "capture dot at end of pattern problem"
made it much more strict overall... (see test cases in controller below).

EDIT: replaced a-z0-9 with [:alnum:] character class
Code:
<?php

class Test extends Controller {

    function Test()
    {
        parent::Controller();
    }
        
    function index()
    {
        $chars = '-.a-zA-Z0-9#!$%&*+/\'=?^_`{}|~';
        $len = strlen($chars);
        $i=0;
        print_r($chars); echo '<br>';
        while ($i<$len)
        {
            preg_match(":[$chars]:", $chars[$i], $matches);
            $i++;
            print_r($matches[0]);
        }
        
        // test on "real" addresses
        $strs = array(
                    "back|to=school~w0w.does+this^work?@sub.email.codeigniter.com",
                    "back{to}school-does+this^work@email.codeigniter.com",
                    'back{to}school#works!hostname@email.codeigniter.com',
                    'h.r@example.com',
                    'h.r@dot-at-end.example.com.',
                    'h.r@double-dot-at-end.example.com..',
                    'h.r@sub.example.com',
                    'h.r@sub-sub.email.example.com',
                    'h-r@example.com',
                    '.hr_does_not_capture_initial_dot@example.com',
                    'h#r@example.com',
                    'h!r@example.com',
                    'h$r@example.com',
                    'h%r@example.com',
                    'h&r;@example.com',
                    'h*r@example.com',
                    'h+r@example.com',
                    'h/r@example.com',
                    "h'r@example.com",
                    'h=r@example.com',
                    'h?r@example.com',
                    'h^r@example.com',
                    'h_r@example.com',
                    'h`r@example.com',
                    'h{r@example.com',
                    'h}r@example.com',
                    'h|r@example.com',
                    'h~r@example.com',
                    'h..r@example.com',
                    'how..r@example.com',
                    'how_wild..rare@example.com',
                    'h...r@example.com',
                    'h.r@example..com',
                    'h.r@tell.me.how.could.the.pattern.not.capture.this.example..com',
                    'h.r@-example-with-inital-dash.com',
                    'h.r@hostname-masks-erroneous-domain.-dash.com',
                    'h.r@dash-at-end-of-tld.com-',
                    'h.r@dash-at-end-of-domain-.com',
                    'h.r@.dot-in-front-of-domain.com',
                    );
        $chars_not_dot = '-a-z0-9#!$%&*+/\'=?^_`{}|~';
        foreach ($strs as $s)
        {
            preg_match_all(";([$chars_not_dot](?:[$chars_not_dot]|[.](?![.]))*)@((?:[[:alnum:]])(?:[-[:alnum:]]*)(?:[[:alnum:]])(?:[.](?![.]))(?:[[:alnum:]])(?:[-[:alnum:]]|[.](?![.]))+(?:[[:alnum:]]));i", $s, $matches);
            $this->_p($s);
            $this->_p($matches);
        }
    
    }
    
    function _p($d) {echo'<pre>';print_r($d);echo'</pre>';}

}

/* End of file test.php */

please test and examine.


Messages In This Thread
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 07:59 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:43 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:50 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:54 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 10:17 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 10:49 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 11:11 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 11:38 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 09:58 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 10:29 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 12:07 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 12:26 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-30-2008, 04:20 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-01-2008, 12:02 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-10-2008, 10:25 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-11-2008, 06:45 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-11-2008, 07:47 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.