Merge branch '2.8' into 3.2
* 2.8: move provider after test update dataProvider function name cast substr result to string and remove empty function use rename dataset provider Add a test to prevent future regressions Switch to `empty` native function to check emptiness remove non relevant test case Switch to `is_string` native method Remove unnecessary parentheses Add a test case to prevent future regressions Move empty condition in return statement Use LF line separator fix coding standard to comply with fabbot Remove malformed EmailValidatorTest + Update UrlValidator test Add empty check on host in other methods + add unit tests [Validator] Allow checkMX() to return false when $host is empty [DI] Prevent AutowirePass from triggering irrelevant deprecations [DI] Fix the xml schema [Translation] avoid creating cache files for fallback locales.
This commit is contained in:
commit
32f264f3c8
@ -325,9 +325,28 @@ class AutowirePass implements CompilerPassInterface
|
|||||||
|
|
||||||
$class = $this->container->getParameterBag()->resolveValue($class);
|
$class = $this->container->getParameterBag()->resolveValue($class);
|
||||||
|
|
||||||
|
if ($deprecated = $definition->isDeprecated()) {
|
||||||
|
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
|
||||||
|
return (E_USER_DEPRECATED === $level || !$prevErrorHandler) ? false : $prevErrorHandler($level, $message, $file, $line);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$e = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$reflector = new \ReflectionClass($class);
|
$reflector = new \ReflectionClass($class);
|
||||||
} catch (\ReflectionException $e) {
|
} catch (\Exception $e) {
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($deprecated) {
|
||||||
|
restore_error_handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $e) {
|
||||||
|
if (!$e instanceof \ReflectionException) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
$reflector = false;
|
$reflector = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +140,8 @@
|
|||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="property" mixed="true">
|
<xsd:complexType name="property" mixed="true">
|
||||||
<xsd:choice minOccurs="0" maxOccurs="1">
|
<xsd:choice minOccurs="0">
|
||||||
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
|
<xsd:element name="property" type="property" maxOccurs="unbounded" />
|
||||||
<xsd:element name="service" type="service" />
|
<xsd:element name="service" type="service" />
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
<xsd:attribute name="type" type="argument_type" />
|
<xsd:attribute name="type" type="argument_type" />
|
||||||
@ -153,8 +153,8 @@
|
|||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="argument" mixed="true">
|
<xsd:complexType name="argument" mixed="true">
|
||||||
<xsd:choice maxOccurs="unbounded">
|
<xsd:choice minOccurs="0">
|
||||||
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
|
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
|
||||||
<xsd:element name="service" type="service" />
|
<xsd:element name="service" type="service" />
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
<xsd:attribute name="type" type="argument_type" />
|
<xsd:attribute name="type" type="argument_type" />
|
||||||
@ -165,10 +165,9 @@
|
|||||||
<xsd:attribute name="strict" type="boolean" />
|
<xsd:attribute name="strict" type="boolean" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="call" mixed="true">
|
<xsd:complexType name="call">
|
||||||
<xsd:choice maxOccurs="unbounded">
|
<xsd:choice minOccurs="0">
|
||||||
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
|
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
|
||||||
<xsd:element name="service" type="service" />
|
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
<xsd:attribute name="method" type="xsd:string" />
|
<xsd:attribute name="method" type="xsd:string" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
@ -493,6 +493,17 @@ class AutowirePassTest extends TestCase
|
|||||||
$this->assertTrue($container->hasDefinition('bar'));
|
$this->assertTrue($container->hasDefinition('bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProcessDoesNotTriggerDeprecations()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true);
|
||||||
|
$container->register('foo', __NAMESPACE__.'\Foo');
|
||||||
|
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
|
||||||
|
|
||||||
|
$pass = new AutowirePass();
|
||||||
|
$pass->process($container);
|
||||||
|
}
|
||||||
|
|
||||||
public function testEmptyStringIsKept()
|
public function testEmptyStringIsKept()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
|
||||||
|
|
||||||
|
@trigger_error('deprecated', E_USER_DEPRECATED);
|
||||||
|
|
||||||
|
class DeprecatedClass
|
||||||
|
{
|
||||||
|
}
|
@ -149,6 +149,17 @@ class TranslatorCacheTest extends TestCase
|
|||||||
$this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production'));
|
$this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGeneratedCacheFilesAreOnlyBelongRequestedLocales()
|
||||||
|
{
|
||||||
|
$translator = new Translator('a', null, $this->tmpDir);
|
||||||
|
$translator->setFallbackLocales(array('b'));
|
||||||
|
$translator->trans('bar');
|
||||||
|
|
||||||
|
$cachedFiles = glob($this->tmpDir.'/*.php');
|
||||||
|
|
||||||
|
$this->assertCount(1, $cachedFiles);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales()
|
public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -386,7 +386,7 @@ EOF
|
|||||||
|
|
||||||
foreach ($this->computeFallbackLocales($locale) as $fallback) {
|
foreach ($this->computeFallbackLocales($locale) as $fallback) {
|
||||||
if (!isset($this->catalogues[$fallback])) {
|
if (!isset($this->catalogues[$fallback])) {
|
||||||
$this->loadCatalogue($fallback);
|
$this->initializeCatalogue($fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
|
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
|
||||||
|
@ -87,7 +87,7 @@ class EmailValidator extends ConstraintValidator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$host = substr($value, strrpos($value, '@') + 1);
|
$host = (string) substr($value, strrpos($value, '@') + 1);
|
||||||
|
|
||||||
// Check for host DNS resource records
|
// Check for host DNS resource records
|
||||||
if ($constraint->checkMX) {
|
if ($constraint->checkMX) {
|
||||||
@ -118,7 +118,7 @@ class EmailValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
private function checkMX($host)
|
private function checkMX($host)
|
||||||
{
|
{
|
||||||
return checkdnsrr($host, 'MX');
|
return '' !== $host && checkdnsrr($host, 'MX');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,6 +130,6 @@ class EmailValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
private function checkHost($host)
|
private function checkHost($host)
|
||||||
{
|
{
|
||||||
return $this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'));
|
return '' !== $host && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,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 (!is_string($host) || !checkdnsrr($host, 'ANY')) {
|
||||||
$this->context->buildViolation($constraint->dnsMessage)
|
$this->context->buildViolation($constraint->dnsMessage)
|
||||||
->setParameter('{{ value }}', $this->formatValue($host))
|
->setParameter('{{ value }}', $this->formatValue($host))
|
||||||
->setCode(Url::INVALID_URL_ERROR)
|
->setCode(Url::INVALID_URL_ERROR)
|
||||||
|
@ -229,4 +229,32 @@ class EmailValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideCheckTypes
|
||||||
|
*/
|
||||||
|
public function testEmptyHostIsNotValid($checkType, $violation)
|
||||||
|
{
|
||||||
|
$this->validator->validate(
|
||||||
|
'foo@bar.fr@',
|
||||||
|
new Email(array(
|
||||||
|
'message' => 'myMessage',
|
||||||
|
$checkType => true,
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
$this
|
||||||
|
->buildViolation('myMessage')
|
||||||
|
->setParameter('{{ value }}', '"foo@bar.fr@"')
|
||||||
|
->setCode($violation)
|
||||||
|
->assertRaised();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideCheckTypes()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('checkMX', Email::MX_CHECK_FAILED_ERROR),
|
||||||
|
array('checkHost', Email::HOST_CHECK_FAILED_ERROR),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,7 @@ class UrlValidatorTest extends ConstraintValidatorTestCase
|
|||||||
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://'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user