diff --git a/UPGRADE-4.1.md b/UPGRADE-4.1.md index 2b23d370cf95e..23591424c695b 100644 --- a/UPGRADE-4.1.md +++ b/UPGRADE-4.1.md @@ -30,6 +30,7 @@ Validator * The `Email::__construct()` 'strict' property is deprecated and will be removed in 5.0. Use 'mode'=>"strict" instead. * Calling `EmailValidator::__construct()` method with a boolean parameter is deprecated and will be removed in 5.0, use `EmailValidator("strict")` instead. + * Deprecated the `checkDNS` and `dnsMessage` options of the `Url` constraint. They will be removed in 5.0. Workflow -------- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 4fdb14222921a..6f1c639013c2b 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -29,7 +29,7 @@ Validator * The `Email::__construct()` 'strict' property has been removed. Use 'mode'=>"strict" instead. * Calling `EmailValidator::__construct()` method with a boolean parameter has been removed, use `EmailValidator("strict")` instead. - + * Removed the `checkDNS` and `dnsMessage` options from the `Url` constraint. Workflow -------- diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index 47365a03105ff..a4259a0b5a5de 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.1.0 +----- + + * Deprecated the `checkDNS` and `dnsMessage` options of the `Url` constraint. They will be removed in 5.0. + 4.0.0 ----- diff --git a/src/Symfony/Component/Validator/Constraints/Url.php b/src/Symfony/Component/Validator/Constraints/Url.php index 988dd19136da6..652a59485b3ce 100644 --- a/src/Symfony/Component/Validator/Constraints/Url.php +++ b/src/Symfony/Component/Validator/Constraints/Url.php @@ -21,18 +21,57 @@ */ class Url extends Constraint { + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_ANY = 'ANY'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_NONE = false; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_A = 'A'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_A6 = 'A6'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_AAAA = 'AAAA'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_CNAME = 'CNAME'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_MX = 'MX'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_NAPTR = 'NAPTR'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_NS = 'NS'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_PTR = 'PTR'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_SOA = 'SOA'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_SRV = 'SRV'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ const CHECK_DNS_TYPE_TXT = 'TXT'; const INVALID_URL_ERROR = '57c2f299-1154-4870-89bb-ef3b1f5ad229'; @@ -42,7 +81,27 @@ class Url extends Constraint ); public $message = 'This value is not a valid URL.'; + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ public $dnsMessage = 'The host could not be resolved.'; public $protocols = array('http', 'https'); + /** + * @deprecated since Symfony 4.1, to be removed in 5.0 + */ public $checkDNS = self::CHECK_DNS_TYPE_NONE; + + 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 and will be removed in 5.0. 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 and will be removed in 5.0.', self::class), E_USER_DEPRECATED); + } + } + + parent::__construct($options); + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 2424e49ad454d..b7c1dc1d776a7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -200,6 +200,8 @@ public function getValidCustomUrls() /** * @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 and will be removed in 5.0. Its false-positive rate is too high to be relied upon. */ public function testCheckDns($violation) { @@ -230,6 +232,8 @@ public function getCheckDns() /** * @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 and will be removed in 5.0. Its false-positive rate is too high to be relied upon. */ public function testCheckDnsByType($type) { @@ -266,6 +270,9 @@ public function getCheckDnsTypes() /** * @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 and will be removed in 5.0. 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 and will be removed in 5.0. */ public function testCheckDnsWithInvalidType() { @@ -278,6 +285,19 @@ public function testCheckDnsWithInvalidType() $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 and will be removed in 5.0. Its false-positive rate is too high to be relied upon. + */ + public function testCheckDnsOptionIsDeprecated() + { + $constraint = new Url(array( + 'checkDNS' => Url::CHECK_DNS_TYPE_NONE, + )); + + $this->validator->validate('http://example.com', $constraint); + } } class EmailProvider