Add empty check on host in other methods + add unit tests
Add empty on host in other methods where checkdnsrr is called and add unit tests to prevent future regressions
This commit is contained in:
parent
6dd023f255
commit
6b0702e52a
@ -138,7 +138,7 @@ class EmailValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
private function checkMX($host)
|
private function checkMX($host)
|
||||||
{
|
{
|
||||||
if (null === $host || '' === $host) {
|
if ('' === $host) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +154,10 @@ class EmailValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
private function checkHost($host)
|
private function checkHost($host)
|
||||||
{
|
{
|
||||||
|
if ('' === $host) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'));
|
return $this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ class UrlValidator extends ConstraintValidator
|
|||||||
if ($constraint->checkDNS) {
|
if ($constraint->checkDNS) {
|
||||||
$host = parse_url($value, PHP_URL_HOST);
|
$host = parse_url($value, PHP_URL_HOST);
|
||||||
|
|
||||||
if (!checkdnsrr($host, 'ANY')) {
|
if ('' === $host || !checkdnsrr($host, 'ANY')) {
|
||||||
if ($this->context instanceof ExecutionContextInterface) {
|
if ($this->context instanceof ExecutionContextInterface) {
|
||||||
$this->context->buildViolation($constraint->dnsMessage)
|
$this->context->buildViolation($constraint->dnsMessage)
|
||||||
->setParameter('{{ value }}', $this->formatValue($host))
|
->setParameter('{{ value }}', $this->formatValue($host))
|
||||||
|
@ -159,4 +159,10 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmptyHostReturnsFalse()
|
||||||
|
{
|
||||||
|
$this->assertFalse($this->validator->checkMX(''));
|
||||||
|
$this->assertFalse($this->validator->checkHost(''));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,7 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
array('http://example.com/exploit.html?<script>alert(1);</script>'),
|
array('http://example.com/exploit.html?<script>alert(1);</script>'),
|
||||||
array('http://example.com/exploit.html?hel lo'),
|
array('http://example.com/exploit.html?hel lo'),
|
||||||
array('http://example.com/exploit.html?not_a%hex'),
|
array('http://example.com/exploit.html?not_a%hex'),
|
||||||
|
array('http:/.com'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user