Skip to content

Commit 6a9fe9b

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: [Request] Ignore invalid IP addresses sent by proxies Able to load big xml files with DomCrawler fixed typo [Form] Fix constraints could be null if not set [Finder] Check PHP version before applying a workaround for a PHP bug fixed CS sort bundles in config:dump-reference command Fixer findings.
2 parents 29e6552 + c2a5340 commit 6a9fe9b

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

Iterator/FilterIterator.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
namespace Symfony\Component\Finder\Iterator;
1313

1414
/**
15-
* This iterator just overrides the rewind method in order to correct a PHP bug.
15+
* This iterator just overrides the rewind method in order to correct a PHP bug,
16+
* which existed before version 5.5.23/5.6.7.
1617
*
17-
* @see https://bugs.php.net/bug.php?id=49104
18+
* @see https://bugs.php.net/68557
1819
*
1920
* @author Alex Bogomazov
2021
*/
@@ -28,18 +29,19 @@ abstract class FilterIterator extends \FilterIterator
2829
*/
2930
public function rewind()
3031
{
32+
if (PHP_VERSION_ID > 50607 || (PHP_VERSION_ID > 50523 && PHP_VERSION_ID < 50600)) {
33+
parent::rewind();
34+
35+
return;
36+
}
37+
3138
$iterator = $this;
3239
while ($iterator instanceof \OuterIterator) {
3340
$innerIterator = $iterator->getInnerIterator();
3441

35-
if ($innerIterator instanceof RecursiveDirectoryIterator) {
36-
if ($innerIterator->isRewindable()) {
37-
$innerIterator->next();
38-
$innerIterator->rewind();
39-
}
40-
} elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
41-
$iterator->getInnerIterator()->next();
42-
$iterator->getInnerIterator()->rewind();
42+
if ($innerIterator instanceof \FilesystemIterator) {
43+
$innerIterator->next();
44+
$innerIterator->rewind();
4345
}
4446
$iterator = $iterator->getInnerIterator();
4547
}

Iterator/RecursiveDirectoryIterator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ public function rewind()
118118
return;
119119
}
120120

121-
// @see https://bugs.php.net/bug.php?id=49104
122-
parent::next();
121+
// @see https://bugs.php.net/68557
122+
if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) {
123+
parent::next();
124+
}
123125

124126
parent::rewind();
125127
}

Tests/FinderTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public function testNotContainsOnDirectory()
467467
* Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
468468
* with inner FilesystemIterator in an invalid state.
469469
*
470-
* @see https://bugs.php.net/bug.php?id=49104
470+
* @see https://bugs.php.net/68557
471471
*/
472472
public function testMultipleLocations()
473473
{
@@ -477,8 +477,12 @@ public function testMultipleLocations()
477477
);
478478

479479
// it is expected that there are test.py test.php in the tmpDir
480-
$finder = $this->buildFinder();
481-
$finder->in($locations)->depth('< 1')->name('test.php');
480+
$finder = new Finder();
481+
$finder->in($locations)
482+
// the default flag IGNORE_DOT_FILES fixes the problem indirectly
483+
// so we set it to false for better isolation
484+
->ignoreDotFiles(false)
485+
->depth('< 1')->name('test.php');
482486

483487
$this->assertCount(1, $finder);
484488
}
@@ -488,7 +492,7 @@ public function testMultipleLocations()
488492
* AppendIterator which does an unnecessary rewind which leaves
489493
* FilterIterator with inner FilesystemIterator in an invalid state.
490494
*
491-
* @see https://bugs.php.net/bug.php?id=49104
495+
* @see https://bugs.php.net/68557
492496
*/
493497
public function testMultipleLocationsWithSubDirectories()
494498
{

Tests/Iterator/FilterIteratorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ public function testFilterFilesystemIterators()
4343
++$c;
4444
}
4545

46-
// This would fail with \FilterIterator but works with Symfony\Component\Finder\Iterator\FilterIterator
47-
// see https://bugs.php.net/bug.php?id=49104
46+
// This would fail in php older than 5.5.23/5.6.7 with \FilterIterator
47+
// but works with Symfony\Component\Finder\Iterator\FilterIterator
48+
// see https://bugs.php.net/68557
4849
$this->assertEquals(1, $c);
4950
}
5051
}

0 commit comments

Comments
 (0)