Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] check for empty host when calling checkdnsrr() #22109

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

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move empty condition in return statement
  • Loading branch information
apetitpa authored and apetitpa committed Mar 27, 2017
commit 1683fee4b3848e8b1cc515573877eea3221a4848
12 changes: 2 additions & 10 deletions 12 src/Symfony/Component/Validator/Constraints/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ public function validate($value, Constraint $constraint)
*/
private function checkMX($host)
{
if ('' === $host) {
return false;
}

return checkdnsrr($host, 'MX');
return ('' !== $host) && checkdnsrr($host, 'MX');
Copy link
Contributor

@Nek- Nek- Mar 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not !empty() check?

Copy link
Author

@apetitpa apetitpa Mar 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well there is a similar check line 45 if (null === $value || '' === $value) that does not use the native empty function so I assumed I should do the same but maybe I was wrong ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid using empty in Symfony.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot interesting, why? (is the reason documented somewhere?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty is just too broad. For instance, it includes the 0 string as being false. Sometimes, that not desirable. So, we prefer to be very explicit about our expectations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parentheses can be removed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this in a minute thank you.

}

/**
Expand All @@ -134,10 +130,6 @@ private function checkMX($host)
*/
private function checkHost($host)
{
if ('' === $host) {
return false;
}

return $this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'));
return ('' !== $host) && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.