Skip to content

Commit fc7a785

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: fixed test [Request] Ignore invalid IP addresses sent by proxies 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. [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 bf31f22 + 6a9fe9b commit fc7a785

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
@@ -468,7 +468,7 @@ public function testNotContainsOnDirectory()
468468
* Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
469469
* with inner FilesystemIterator in an invalid state.
470470
*
471-
* @see https://bugs.php.net/bug.php?id=49104
471+
* @see https://bugs.php.net/68557
472472
*/
473473
public function testMultipleLocations()
474474
{
@@ -478,8 +478,12 @@ public function testMultipleLocations()
478478
);
479479

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

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

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)