8000 Merge branch '2.7' into 2.8 · symfony/symfony@8d0cfa4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d0cfa4

Browse files
Merge branch '2.7' into 2.8
* 2.7: 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] Fix the xml schema [Translation] avoid creating cache files for fallback locales.
2 parents 91b025a + 2adfb37 commit 8d0cfa4

File tree

7 files changed

+52
-13
lines changed

7 files changed

+52
-13
lines changed

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
</xsd:complexType>
146146

147147
<xsd:complexType name="property" mixed="true">
148-
<xsd:choice minOccurs="0" maxOccurs="1">
149-
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
148+
<xsd:choice minOccurs="0">
149+
<xsd:element name="property" type="property" maxOccurs="unbounded" />
150150
<xsd:element name="service" type="service" />
151151
</xsd:choice>
152152
<xsd:attribute name="type" type="argument_type" />
@@ -158,8 +158,8 @@
158158
</xsd:complexType>
159159

160160
<xsd:complexType name="argument" mixed="true">
161-
<xsd:choice maxOccurs="unbounded">
162-
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
161+
<xsd:choice minOccurs="0">
162+
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
163163
<xsd:element name="service" type="service" />
164164
</xsd:choice>
165165
<xsd:attribute name="type" type="argument_type" />
@@ -170,10 +170,9 @@
170170
<xsd:attribute name="strict" type="boolean" />
171171
</xsd:complexType>
172172

173-
<xsd:complexType name="call" mixed="true">
174-
<xsd:choice maxOccurs="unbounded">
175-
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
176-
<xsd:element name="service" type="service" />
173+
<xsd:complexType name="call">
174+
<xsd:choice minOccurs="0">
175+
<xsd:element name="argument" type="argument" maxOccurs="unbounded" />
177176
</xsd:choice>
178177
<xsd:attribute name="method" type="xsd:string" />
179178
</xsd:complexType>

src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ public function testDifferentTranslatorsForSameLocaleDoNotOverwriteEachOthersCac
149149
$this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production'));
150150
}
151151

152+
public function testGeneratedCacheFilesAreOnlyBelongRequestedLocales()
153+
{
154+
$translator = new Translator('a', null, $this->tmpDir);
155+
$translator->setFallbackLocales(array('b'));
156+
$translator->trans('bar');
157+
158+
$cachedFiles = glob($this->tmpDir.'/*.php');
159+
160+
$this->assertCount(1, $cachedFiles);
161+
}
162+
152163
public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales()
153164
{
154165
/*

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ private function loadFallbackCatalogues($locale)
424424

425425
foreach ($this->computeFallbackLocales($locale) as $fallback) {
426426
if (!isset($this->catalogues[$fallback])) {
427-
$this->loadCatalogue($fallback);
427+
$this->initializeCatalogue($fallback);
428428
}
429429

430430
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());

src/Symfony/Component/Validator/Constraints/EmailValidator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function validate($value, Constraint $constraint)
9393
return;
9494
}
9595

96-
$host = substr($value, strrpos($value, '@') + 1);
96+
$host = (string) substr($value, strrpos($value, '@') + 1);
9797

9898
// Check for host DNS resource records
9999
if ($constraint->checkMX) {
@@ -138,7 +138,7 @@ public function validate($value, Constraint $constraint)
138138
*/
139139
private function checkMX($host)
140140
{
141-
return checkdnsrr($host, 'MX');
141+
return '' !== $host && checkdnsrr($host, 'MX');
142142
}
143143

144144
/**
@@ -150,6 +150,6 @@ private function checkMX($host)
150150
*/
151151
private function checkHost($host)
152152
{
153-
return $this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'));
153+
return '' !== $host && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
154154
}
155155
}

src/Symfony/Component/Validator/Constraints/UrlValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function validate($value, Constraint $constraint)
8282
if ($constraint->checkDNS) {
8383
$host = parse_url($value, PHP_URL_HOST);
8484

85-
if (!checkdnsrr($host, 'ANY')) {
85+
if (!is_string($host) || !checkdnsrr($host, 'ANY')) {
8686
if ($this->context instanceof ExecutionContextInterface) {
8787
$this->context->buildViolation($constraint->dnsMessage)
8888
->setParameter('{{ value }}', $this->formatValue($host))

src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,32 @@ public function testHostnameIsProperlyParsed()
159159

160160
$this->assertNoViolation();
161161
}
162+
163+
/**
164+
* @dataProvider provideCheckTypes
165+
*/
166+
public function testEmptyHostIsNotValid($checkType, $violation)
167+
{
168+
$this->validator->validate(
169+
'foo@bar.fr@',
170+
new Email(array(
171+
'message' => 'myMessage',
172+
$checkType => true,
173+
))
174+
);
175+
176+
$this
177+
->buildViolation('myMessage')
178+
->setParameter('{{ value }}', '"foo@bar.fr@"')
179+
->setCode($violation)
180+
->assertRaised();
181+
}
182+
183+
public function provideCheckTypes()
184+
{
185+
return array(
186+
array('checkMX', Email::MX_CHECK_FAILED_ERROR),
187+
array('checkHost', Email::HOST_CHECK_FAILED_ERROR),
188+
);
189+
}
162190
}

src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public function getInvalidUrls()
172172
array('http://example.com/exploit.html?<script>alert(1);</script>'),
173173
array('http://example.com/exploit.html?hel lo'),
174174
array('http://example.com/exploit.html?not_a%hex'),
175+
array('http://'),
175176
);
176177
}
177178

0 commit comments

Comments
 (0)
0