Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email validation allows spaces #28233

Closed
kskrlin opened this issue Apr 16, 2019 · 12 comments
Closed

Email validation allows spaces #28233

kskrlin opened this issue Apr 16, 2019 · 12 comments

Comments

@kskrlin
Copy link

kskrlin commented Apr 16, 2019

  • Laravel Version: 5.8.11
  • PHP Version: 7.3.4

Description:

Email validation doesn't fail when email contains spaces:
"test @ example .com", but fails here "test@example. com".
This seems as big bug to me.

Steps To Reproduce:

Tinker:

$validator = \Validator::make(['email' => 'test @ example .com'], ['email' => 'email']);

$validator->fails(); // throws false
@driesvints
Copy link
Member

Laravel makes use of https://github.com/egulias/EmailValidator/ to do email validation so if you feel that this is a bug please open up an issue on their issue tracker: https://github.com/egulias/EmailValidator/issues

@kskrlin
Copy link
Author

kskrlin commented Apr 16, 2019

I don't "feel" this is a bug; this is a bug. Emails aren't allowed to have spaces.

Why package wasn't checked and/or tested before it was included into framework?
I will report this as issue, but your responsibility is also to validate packages before they are used as core, instead of just closing issues when you feel like it and referencing to others.

@devcircus
Copy link
Contributor

devcircus commented Apr 16, 2019

According to the official spec, the local part of an email is allowed to have spaces. The domain should not though.

@kskrlin
Copy link
Author

kskrlin commented Apr 16, 2019

Why is this package even used for email validation?
Is there any valid reason? Default PHP filters are too strict?

Because, after we tested some strings, we get these results:
' @example.com' - fails with php filter_var, passes with package
'###@example.com' - passes with both
'$šte/-{st+email#@example.com' - fails with php filter_var, passes with package

This package only fails when there are more than 1 "@" symbol, quotes or space between dot and tld.

Why is this package considered "better" approach than default PHP filter_var function or even some other package?

Also, this bug with spaces is since 2014.

@dwightwatson
Copy link
Contributor

Looks like this package is validating emails with spaces in the domain part.

(new EmailValidator)->isValid('dwight@ gmail.com', new RFCValidation) // true

This was problem was discussed further in #27875 but doesn't look like there's going to be any change here.

The package was introduced in #26503 so I suppose the other option is to break out your own custom email validation rule and use it in place.

@Dalamar
Copy link

Dalamar commented Nov 21, 2019

According to the official spec, the local part of an email is allowed to have spaces.

It is not.
https://tools.ietf.org/html/rfc2822
Appendix B. Differences from earlier standards
19. CFWS within local-parts and domains not allowed.*

@Dalamar
Copy link

Dalamar commented Nov 21, 2019

Please reopen this issue as the bug still exists and even affects the out-of-the-box registration flow.

I suggest making filter_var the default email validator.
Though we can still take an advantage of egulias/email-validator package by applying validation styles to email validator rules (rfc, dns, spoof, strict)

@michabbb
Copy link

michabbb commented Jul 7, 2022

hi there, as this problem still exists, i would be happy to know the optimal way to validate an email address in laravel, because using email:rfc obviously is useless. i guess email:strict is the best option to choose?

@dammixyz
Copy link

03:13 AM, September 30th, 2022. This problem still exists and it nearly ruined my project! Come on guys do something!

@michabbb
Copy link

@dammixyz for now, i am good with 'required|email:strict,dns|not_regex:/[ÄäÜüÖö]/'

@dammixyz
Copy link

dammixyz commented Oct 11, 2022 via email

@fershopls
Copy link

@dammixyz for now, i am good with 'required|email:strict,dns|not_regex:/[ÄäÜüÖö]/'

This should be the default :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants