Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How consistent is FILTER_VALIDATE_EMAIL?

Sample valid e-mail address:

"this is a valid address"@example.com

PHP code:

<?php
header('Content-Type: text/plain');

$email = '"this is a valid address"@example.com';
$checked = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($email, $checked);

Output on one server: (PHP Version 5.2.6):

string(37) ""this is a valid address"@example.com"
string(37) ""this is a valid address"@example.com"

phpinfo():

Input Validation and Filtering      enabled
Revision                            $Revision: 1.52.2.42 $

Directive             Local Value   Master Value
filter.default        unsafe_raw    unsafe_raw
filter.default_flags  no value      no value

Output on another server (PHP Version 5.3.3):

string(37) ""this is a valid address"@example.com"
bool(false)

phpinfo():

Input Validation and Filtering      enabled
Revision                            $Revision: 298196 $

Directive             Local Value   Master Value
filter.default        unsafe_raw    unsafe_raw
filter.default_flags  no value      no value

I cannot see anything in the documentation to suggest that this has changed, so perhaps it's some other configuration setting.

like image 966
TRiG Avatar asked Nov 21 '12 13:11

TRiG


1 Answers

As you can see on http://3v4l.org/vKONS the usage of the filter FILTER_VALIDATE_EMAIL it is not consistent!

http://3v4l.org/vKONS outputs for PHP 5.2.0, 5.2.14 - 5.2.17, 5.3.3 - 5.3.18, 5.4.0 - 5.4.8

string(37) ""this is a valid address"@example.com" 
bool(false)

and for 5.2.1 - 5.2.13, 5.3.0 - 5.3.2

string(37) ""this is a valid address"@example.com" 
string(37) ""this is a valid address"@example.com"

It is remarkable that it worked for 5.2.0 but not 5.2.1-5.2.13 and then again for 5.2.14!!!

Btw 3v4l.org is a great resource to check such behavior changes across all available PHP versions.

There are several bugs open including the term FILTER_VALIDATE_EMAIL, but none seems to match your kind of error. You might add it to the PHP bugtracker...

like image 98
powtac Avatar answered Sep 21 '22 03:09

powtac