Problem/Motivation

Split of symfony 2.5 (#2278353: Update to Symfony 2.5)
The validator API in symfony was rewritten from using filter_var():

filter_var('bob@example.com', FILTER_VALIDATE_EMAIL);

to either using a simple regex (not RFC compliant, but faster) or an external library: egulias/EmailValidator (which is slower but standard compliant).

Proposed resolution

All people on #2278353: Update to Symfony 2.5 (comment 31 and following) favored the standard compliant external library, let's get it into core.

Edit: just for historical accuracy because I can guarantee noone will actually read the linked issue, this is not true. #2278353-31: Update to Symfony 2.5 named three options, raised questions, #2278353-32: Update to Symfony 2.5 added more questions, #2278353-33: Update to Symfony 2.5 reminded that punycode needs to validate, #2278353-34: Update to Symfony 2.5 unilaterally decided to end the discussion and do this.

Edit: #2278353-79: Update to Symfony 2.5 votes to make this an optional upgrade by falling back onto filter_var() in an override class.

Email-validator ships with the standards which have non-proper line-endings, so git might complain.

Remaining tasks

User interface changes

API changes

Comments

dawehner’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new7.26 KB
composer require egulias/email-validator 1.0.x-dev                                                                                                                                                                                                           
dawehner’s picture

Issue summary: View changes
dawehner’s picture

Issue summary: View changes
StatusFileSize
new148.36 KB

This time done properly ...

dawehner’s picture

Issue summary: View changes
StatusFileSize
new148.36 KB
new75.27 KB

Let's give it another try:

composer require egulias/email-validator 1.1.1

effulgentsia’s picture

For reference, this is the Symfony commit that started using this library: https://github.com/symfony/symfony/commit/3368630482c0f5f5c0ebaf08e64347....

dawehner’s picture

Priority: Normal » Major
StatusFileSize
new76.01 KB

Just another ordinary reroll ... (looking forward to get rid of the vendor shipped with git)
I consider this as major now, given that it blocks a critical (we can't release with an old version of symfony which will not be supported quite fast).

dries’s picture

Ideally, this would be fixed in PHP but sadly, that is not a realistic expectation. It seems like a lot of extra code but in general, I prefer to add a library rather than having to subclass Symfony to change its behavior. I'm not thrilled with it but all things considered, I'm ok with adding this library.

dawehner’s picture

Yeah it is a shame that a programming language dealing with basically just web is not capable to come up with proper implementations.

I prefer to add a library rather than having to subclass Symfony to change its behavior.

Me too, those kind of things are just non-trivial to get right.

The actual library (without tests, composer) is not bigger than 1k lines though.

effulgentsia’s picture

Assigned: dries » Unassigned

Unassigning Dries, since he answered in #7.

chx’s picture

Edit: nevermind.

sun’s picture

Title: Bring in egulias/EmailValidator for RFC compliant » Bring in egulias/EmailValidator for RFC compliant email address validation

+1 in general. PHP core always lacked behind reality, and any amount of PCRE is not able to reliably deal with advanced characteristics like IDNs, IPv6, etc.pp.

That said, I didn't really study the library's code, so I don't want to RTBC.

Lastly, it would be great to adjust our .gitignore to exclude:

core/vendor/**/tests

We really don't need all of those upstream tests in our repo at all.

dawehner’s picture

We really don't need all of those upstream tests in our repo at all.

What I think we really want is to not include all those libraries at all in the first place. The tests itself
are a great source to understand how to use all the code the libraries provide.

chx’s picture

Issue summary: View changes
pfrenssen’s picture

StatusFileSize
new93.34 KB

Updated patch to the newer 1.2.0 release of the library.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

1.2 is certainly more sane

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review

Here's the relevant code from Symfony's upgrade to 2.5:

diff --git a/core/vendor/symfony/validator/Symfony/Component/Validator/Constraints/EmailValidator.php 
-        $valid = filter_var($value, FILTER_VALIDATE_EMAIL);
...
+        if ($constraint->strict && class_exists('\Egulias\EmailValidator\EmailValidator')) {
+            $strictValidator = new StrictEmailValidator();
+            $valid = $strictValidator->isValid($value, false);
+        } elseif ($constraint->strict === true) {
+            throw new \RuntimeException('Strict email validation requires egulias/email-validator');
+        } else {
+            $valid = preg_match('/.+\@.+\..+/', $value);
+        }

#7 answers that we don't want to override this class, but I'm sitting here at TCDrupal near alexpott and he's asking what would be wrong with just allowing the very permissive regex at the bottom to operate.

dawehner’s picture

I totally understand and struggled as well, why do we need 1000 lines of code to properly validate
a mail adress, given that noone really complained about filter_var()

#7 answers that we don't want to override this class, but I'm sitting here at TCDrupal near alexpott and he's asking what would be wrong with just allowing the very permissive regex at the bottom to operate.

Their idea is described good in one sentence (https://github.com/symfony/symfony/issues/1581#issuecomment-50854181)
The decision was to be either simple and (fully) non-strict or strict, and not half-ways, which would be the filter_var option.

Once you use the really simple regex here you start to get problems as this is validation for mail adresses of actual users. Do we really want to just allow people
to make typos and then make it impossible for them to actually login, as their one-time mail was not sent out properly?

pfrenssen’s picture

Issue tags: +Drupalaton 2014
dawehner’s picture

effulgentsia’s picture

Re #19: why does this issue need to be blocked on that? What's the relationship between the two?

dawehner’s picture

Re #19: why does this issue need to be blocked on that? What's the relationship between the two?

Well, I just want to reduce the costs the community has to do for rerolls of various composer.json files.
If these changes are not totally in random order these costs can be reduced as they are known beforehand

Status: Needs review » Needs work

The last submitted patch, 14: 2313669-email_validator-14.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new93.32 KB

This is just a reroll for now.

neclimdul’s picture

Issue summary: View changes

link to comments

droplet’s picture

Also the front-end HTML5 validation has diff results in diff browsers, therefore adding users programmatically may not pass frontend checking.

http://trac.webkit.org/browser/trunk/Source/WebCore/html/EmailInputType....
http://hg.mozilla.org/mozilla-central/file/805aff291ec2/content/html/con...

Status: Needs review » Needs work

The last submitted patch, 24: email_validator-2313669-24.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new93.32 KB

Rerolling... There were conflicts in the composer.lock and core/vendor/composer/installed.json files.

cilefen’s picture

Priority: Major » Critical
Status: Needs review » Reviewed & tested by the community

This patch is holding up at least 2 criticals, so it is critical.

This patch is in-scope and does exactly what it says. It is agreed in the parent issue that this library is necessary to provide strict email address validation with Symfony 2.5+.

cilefen’s picture

Issue summary: View changes
Priority: Critical » Major
Status: Reviewed & tested by the community » Needs review

See #2278353-79: Update to Symfony 2.5: @dawehner @berdir and I discussed the email validation question on IRC and concluded that since valid_email_address() still exists and uses filter_var() then it makes no sense to have the validator class act differently. Because of that, I propose we add a new validator that overrides Symfony's that does filter_var().

This issue should be considered an upgrade to email validation.

fago’s picture

Why not simply update valid_email_address() to use the constraint as well?

cilefen’s picture

@fago Personally, I like that idea. We should do that. But I don't want Symfony 2.5 to depend on this issue.

effulgentsia’s picture

Assigned: Unassigned » alexpott
Status: Needs review » Reviewed & tested by the community

Dries rejected #31 in #7.

The question that's left here is whether to add the library or do what alexpott asked about in #16 (I typed up the comment, but it was his question): use the fallback to the very permissive regex check in core, and allow contrib modules or sites that want the robust validation to add the library themselves.

I think #26 might be a good answer to not falling back to the very permissive regex: i.e., you could enter an address on one browser/device that will fail client-side validation on another one.

So, assigning this one to alexpott to see if that answers his question adequately, or if he wants to kick it back to us, or to Dries.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 8071855 and pushed to 8.0.x. Thanks!

Testing 10000 iterations with fabien@symfony.com
0.082918167114258 seconds with filter_var
0.44279789924622 seconds with EmailValidator + instantiation
0.42330503463745 seconds with EmailValidator once instanced

Ran https://github.com/egulias/EmailValidator/blob/master/tests/egulias/Perf... considering this will not be run 100's of times per request.

  • alexpott committed 8071855 on 8.0.x
    Issue #2313669 by dawehner, hussainweb, pfrenssen: Bring in egulias/...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.