Skip to content

Commit a72e3ec

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: fixed test [Request] Ignore invalid IP addresses sent by proxies [EventDispatcher] TraceableEventDispatcher resets listener priorities Throw for missing container extensions [TwigBridge] add missing unit tests (AppVariable) 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 add defaultNull to version sort bundles in config:dump-reference command Fixer findings. Profiler CSS position conflicts with JS detection [Translation][Writer] avoid calling setBackup if the dumper is not an instance of FileDumper. [FrameworkBundle] Compute the kernel root hash only one time
2 parents 688fa04 + 729cbb3 commit a72e3ec

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
@@ -462,7 +462,7 @@ public function testNotContainsOnDirectory()
462462
* Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
463463
* with inner FilesystemIterator in an invalid state.
464464
*
465-
* @see https://bugs.php.net/bug.php?id=49104
465+
* @see https://bugs.php.net/68557
466466
*/
467467
public function testMultipleLocations()
468468
{
@@ -472,8 +472,12 @@ public function testMultipleLocations()
472472
);
473473

474474
// it is expected that there are test.py test.php in the tmpDir
475-
$finder = $this->buildFinder();
476-
$finder->in($locations)->depth('< 1')->name('test.php');
475+
$finder = new Finder();
476+
$finder->in($locations)
477+
// the default flag IGNORE_DOT_FILES fixes the problem indirectly
478+
// so we set it to false for better isolation
479+
->ignoreDotFiles(false)
480+
->depth('< 1')->name('test.php');
477481

478482
$this->assertCount(1, $finder);
479483
}
@@ -483,7 +487,7 @@ public function testMultipleLocations()
483487
* AppendIterator which does an unnecessary rewind which leaves
484488
* FilterIterator with inner FilesystemIterator in an invalid state.
485489
*
486-
* @see https://bugs.php.net/bug.php?id=49104
490+
* @see https://bugs.php.net/68557
487491
*/
488492
public function testMultipleLocationsWithSubDirectories()
489493
{

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)