-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Closed
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
74629a4
[Validator] Allow checkMX() to return false when $host is empty
b7f6db6
Add empty check on host in other methods + add unit tests
af3b0d9
Remove malformed EmailValidatorTest + Update UrlValidator test
fd9843a
fix coding standard to comply with fabbot
61e2439
Use LF line separator
1683fee
Move empty condition in return statement
00f8e7b
Add a test case to prevent future regressions
6a919dd
Remove unnecessary parentheses
628c2d8
Switch to `is_string` native method
794f63d
remove non relevant test case
756f9ce
Switch to `empty` native function to check emptiness
b6f471a
Add a test to prevent future regressions
7defce7
rename dataset provider
c9b4613
cast substr result to string and remove empty function use
67e1dcc
update dataProvider function name
bb05115
move provider after test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Move empty condition in return statement
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parentheses can be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll fix this in a minute thank you. |
||
} | ||
|
||
/** | ||
|
@@ -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'))); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
!empty()
check?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 nativeempty
function so I assumed I should do the same but maybe I was wrong ?There was a problem hiding this comment.
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.There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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 the0
string as beingfalse
. Sometimes, that not desirable. So, we prefer to be very explicit about our expectations.