php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50158 FILTER_VALIDATE_EMAIL fails with valid addresses containing = or ?
Submitted: 2009-11-12 14:56 UTC Modified: 2009-11-15 16:53 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: andrew dot nicols at luns dot net dot uk Assigned: pierrick (profile)
Status: Closed Package: Filter related
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
 [2009-11-12 14:56 UTC] andrew dot nicols at luns dot net dot uk
Description:
------------
The filter_var function, when used with FILTER_VALIDATE_EMAIL marks an email address with an = in it as invalid.

According to RFCs 822, 2822 and 5322, = is a valid component to the local-part of an e-mail address.

Reproduce code:
---------------
<?php    
    
$email_address = "test=mail@example.com";    
var_dump(filter_var($email_address, FILTER_VALIDATE_EMAIL));    
                                                                
$email_address = "test-mail@example.com";    
var_dump(filter_var($email_address, FILTER_VALIDATE_EMAIL));    
    
$email_address = "test+mail@example.com";    
var_dump(filter_var($email_address, FILTER_VALIDATE_EMAIL));    
                                                                        
?>


Expected result:
----------------
string(21) "test-mail@example.com"
string(21) "test-mail@example.com"
string(21) "test+mail@example.com"


Actual result:
--------------
bool(false)
string(21) "test+mail@example.com"
string(21) "test+mail@example.com"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-12 14:57 UTC] andrew dot nicols at luns dot net dot uk
Copy/paste bug on my behalf. The expected result is:

string(21) "test=mail@example.com"
string(21) "test-mail@example.com"
string(21) "test+mail@example.com"
 [2009-11-12 17:07 UTC] jani@php.net
Yes, = is valid. And also any of these too:

! $ & * - = ^ ` | ~ # % ' + / ? _ { } 


 [2009-11-12 17:12 UTC] jani@php.net
Quick check to the regexp used shows these are missing from allowed part in it: = ?   

 [2009-11-14 17:25 UTC] pierrick@php.net
Patch available at:

http://www.adoy.net/php/50158.patch

This patch add = and ? to the local-part validation according to RFC2822





 [2009-11-15 16:53 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=290791
Log: - Fixed bug #50158 (FILTER_VALIDATE_EMAIL fails with valid addresses containing = or ?).
  (Patch by Pierrick)
 [2009-11-15 16:53 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Thanks for the patch.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC