X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fvalidator%2FConstraints%2FUrlValidator.php;h=222597ed10f41f568d2696cea6b7bd463797dbc8;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=7ab72bcff63a1cba54136b00ff74cced72f28a12;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/validator/Constraints/UrlValidator.php b/vendor/symfony/validator/Constraints/UrlValidator.php index 7ab72bcff..222597ed1 100644 --- a/vendor/symfony/validator/Constraints/UrlValidator.php +++ b/vendor/symfony/validator/Constraints/UrlValidator.php @@ -11,9 +11,9 @@ namespace Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Exception\InvalidOptionsException; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** @@ -23,9 +23,9 @@ class UrlValidator extends ConstraintValidator { const PATTERN = '~^ (%s):// # protocol - (([\pL\pN-]+:)?([\pL\pN-]+)@)? # basic auth + (([\.\pL\pN-]+:)?([\.\pL\pN-]+)@)? # basic auth ( - ([\pL\pN\pS-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name + ([\pL\pN\pS\-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name | # or \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address | # or @@ -48,7 +48,7 @@ class UrlValidator extends ConstraintValidator throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Url'); } - if (null === $value) { + if (null === $value || '' === $value) { return; } @@ -64,36 +64,45 @@ class UrlValidator extends ConstraintValidator $pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols)); if (!preg_match($pattern, $value)) { - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->message) - ->setParameter('{{ value }}', $this->formatValue($value)) - ->setCode(Url::INVALID_URL_ERROR) - ->addViolation(); - } else { - $this->buildViolation($constraint->message) - ->setParameter('{{ value }}', $this->formatValue($value)) - ->setCode(Url::INVALID_URL_ERROR) - ->addViolation(); - } + $this->context->buildViolation($constraint->message) + ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Url::INVALID_URL_ERROR) + ->addViolation(); return; } if ($constraint->checkDNS) { + // backwards compatibility + if (true === $constraint->checkDNS) { + $constraint->checkDNS = Url::CHECK_DNS_TYPE_ANY; + @trigger_error(sprintf('Use of the boolean TRUE for the "checkDNS" option in %s is deprecated. Use Url::CHECK_DNS_TYPE_ANY instead.', Url::class), E_USER_DEPRECATED); + } + + if (!in_array($constraint->checkDNS, array( + 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, + ))) { + throw new InvalidOptionsException(sprintf('Invalid value for option "checkDNS" in constraint %s', get_class($constraint)), array('checkDNS')); + } + $host = parse_url($value, PHP_URL_HOST); - if (!checkdnsrr($host, 'ANY')) { - if ($this->context instanceof ExecutionContextInterface) { - $this->context->buildViolation($constraint->dnsMessage) - ->setParameter('{{ value }}', $this->formatValue($host)) - ->setCode(Url::INVALID_URL_ERROR) - ->addViolation(); - } else { - $this->buildViolation($constraint->dnsMessage) - ->setParameter('{{ value }}', $this->formatValue($host)) - ->setCode(Url::INVALID_URL_ERROR) - ->addViolation(); - } + if (!is_string($host) || !checkdnsrr($host, $constraint->checkDNS)) { + $this->context->buildViolation($constraint->dnsMessage) + ->setParameter('{{ value }}', $this->formatValue($host)) + ->setCode(Url::INVALID_URL_ERROR) + ->addViolation(); } } }