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] Remove checkDNS option in Url #31681

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

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
84 changes: 0 additions & 84 deletions 84 src/Symfony/Component/Validator/Constraints/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,103 +22,19 @@
*/
class Url extends Constraint
{
/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_ANY = 'ANY';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_NONE = false;

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_A = 'A';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_A6 = 'A6';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_AAAA = 'AAAA';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_CNAME = 'CNAME';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_MX = 'MX';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_NAPTR = 'NAPTR';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_NS = 'NS';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_PTR = 'PTR';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_SOA = 'SOA';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_SRV = 'SRV';

/**
* @deprecated since Symfony 4.1
*/
const CHECK_DNS_TYPE_TXT = 'TXT';

const INVALID_URL_ERROR = '57c2f299-1154-4870-89bb-ef3b1f5ad229';

protected static $errorNames = [
self::INVALID_URL_ERROR => 'INVALID_URL_ERROR',
];

public $message = 'This value is not a valid URL.';

/**
* @deprecated since Symfony 4.1
*/
public $dnsMessage = 'The host could not be resolved.';
public $protocols = ['http', 'https'];

/**
* @deprecated since Symfony 4.1
*/
public $checkDNS = self::CHECK_DNS_TYPE_NONE;
public $relativeProtocol = false;
public $normalizer;

public function __construct($options = null)
{
if (\is_array($options)) {
if (\array_key_exists('checkDNS', $options)) {
@trigger_error(sprintf('The "checkDNS" option in "%s" is deprecated since Symfony 4.1. Its false-positive rate is too high to be relied upon.', self::class), E_USER_DEPRECATED);
}
if (\array_key_exists('dnsMessage', $options)) {
@trigger_error(sprintf('The "dnsMessage" option in "%s" is deprecated since Symfony 4.1.', self::class), E_USER_DEPRECATED);
}
}

parent::__construct($options);

if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
Expand Down
29 changes: 0 additions & 29 deletions 29 src/Symfony/Component/Validator/Constraints/UrlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\InvalidOptionsException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

Expand Down Expand Up @@ -77,33 +76,5 @@ public function validate($value, Constraint $constraint)

return;
}

if ($constraint->checkDNS) {
if (!\in_array($constraint->checkDNS, [
Url::CHECK_DNS_TYPE_ANY,
Url::CHECK_DNS_TYPE_A,
Url::CHECK_DNS_TYPE_A6,
Url::CHECK_DNS_TYPE_AAAA,
Url::CHECK_DNS_TYPE_CNAME,
Url::CHECK_DNS_TYPE_MX,
Url::CHECK_DNS_TYPE_NAPTR,
Url::CHECK_DNS_TYPE_NS,
Url::CHECK_DNS_TYPE_PTR,
Url::CHECK_DNS_TYPE_SOA,
Url::CHECK_DNS_TYPE_SRV,
Url::CHECK_DNS_TYPE_TXT,
], true)) {
throw new InvalidOptionsException(sprintf('Invalid value for option "checkDNS" in constraint %s', \get_class($constraint)), ['checkDNS']);
}

$host = parse_url($value, PHP_URL_HOST);

if (!\is_string($host) || !checkdnsrr($host, $constraint->checkDNS)) {
$this->context->buildViolation($constraint->dnsMessage)
->setParameter('{{ value }}', $this->formatValue($host))
->setCode(Url::INVALID_URL_ERROR)
->addViolation();
}
}
}
}
106 changes: 0 additions & 106 deletions 106 src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@

namespace Symfony\Component\Validator\Tests\Constraints;

use Symfony\Bridge\PhpUnit\DnsMock;
use Symfony\Component\Validator\Constraints\Url;
use Symfony\Component\Validator\Constraints\UrlValidator;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

/**
* @group dns-sensitive
*/
class UrlValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator()
Expand Down Expand Up @@ -283,108 +279,6 @@ public function getValidCustomUrls()
['git://[::1]/'],
];
}

/**
* @dataProvider getCheckDns
* @requires function Symfony\Bridge\PhpUnit\DnsMock::withMockedHosts
* @group legacy
* @expectedDeprecation The "checkDNS" option in "Symfony\Component\Validator\Constraints\Url" is deprecated since Symfony 4.1. Its false-positive rate is too high to be relied upon.
*/
public function testCheckDns($violation)
{
DnsMock::withMockedHosts(['example.com' => [['type' => $violation ? '' : 'A']]]);

$constraint = new Url([
'checkDNS' => 'ANY',
'dnsMessage' => 'myMessage',
]);

$this->validator->validate('http://example.com', $constraint);

if (!$violation) {
$this->assertNoViolation();
} else {
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"example.com"')
->setCode(Url::INVALID_URL_ERROR)
->assertRaised();
}
}

public function getCheckDns()
{
return [[true], [false]];
}

/**
* @dataProvider getCheckDnsTypes
* @requires function Symfony\Bridge\PhpUnit\DnsMock::withMockedHosts
* @group legacy
* @expectedDeprecation The "checkDNS" option in "Symfony\Component\Validator\Constraints\Url" is deprecated since Symfony 4.1. Its false-positive rate is too high to be relied upon.
*/
public function testCheckDnsByType($type)
{
DnsMock::withMockedHosts(['example.com' => [['type' => $type]]]);

$constraint = new Url([
'checkDNS' => $type,
'dnsMessage' => 'myMessage',
]);

$this->validator->validate('http://example.com', $constraint);

$this->assertNoViolation();
}

public function getCheckDnsTypes()
{
return [
['ANY'],
['A'],
['A6'],
['AAAA'],
['CNAME'],
['MX'],
['NAPTR'],
['NS'],
['PTR'],
['SOA'],
['SRV'],
['TXT'],
];
}

/**
* @expectedException \Symfony\Component\Validator\Exception\InvalidOptionsException
* @requires function Symfony\Bridge\PhpUnit\DnsMock::withMockedHosts
* @group legacy
* @expectedDeprecation The "checkDNS" option in "Symfony\Component\Validator\Constraints\Url" is deprecated since Symfony 4.1. Its false-positive rate is too high to be relied upon.
* @expectedDeprecation The "dnsMessage" option in "Symfony\Component\Validator\Constraints\Url" is deprecated since Symfony 4.1.
*/
public function testCheckDnsWithInvalidType()
{
DnsMock::withMockedHosts(['example.com' => [['type' => 'A']]]);

$constraint = new Url([
'checkDNS' => 'BOGUS',
'dnsMessage' => 'myMessage',
]);

$this->validator->validate('http://example.com', $constraint);
}

/**
* @group legacy
* @expectedDeprecation The "checkDNS" option in "Symfony\Component\Validator\Constraints\Url" is deprecated since Symfony 4.1. Its false-positive rate is too high to be relied upon.
*/
public function testCheckDnsOptionIsDeprecated()
{
$constraint = new Url([
'checkDNS' => Url::CHECK_DNS_TYPE_NONE,
]);

$this->validator->validate('http://example.com', $constraint);
}
}

class EmailProvider
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.