Skip to content

Commit 45b68e0

Browse files
alquercifabpot
authored andcommitted
[Finder] Fix unexpected duplicate sub path related AppendIterator issue
1 parent e789a02 commit 45b68e0

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ public function current()
3838
{
3939
return new SplFileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname());
4040
}
41+
42+
public function rewind()
43+
{
44+
// @see https://bugs.php.net/bug.php?id=49104
45+
parent::next();
46+
47+
parent::rewind();
48+
}
4149
}

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,30 @@ public function testMultipleLocations()
459459

460460
$this->assertEquals(1, count($finder));
461461
}
462+
463+
/**
464+
* Searching in multiple locations with sub directories involves
465+
* AppendIterator which does an unnecessary rewind which leaves
466+
* FilterIterator with inner FilesystemIterator in an ivalid state.
467+
*
468+
* @see https://bugs.php.net/bug.php?id=49104
469+
*/
470+
public function testMultipleLocationsWithSubDirectories()
471+
{
472+
$locations = array(
473+
__DIR__.'/Fixtures/one',
474+
self::$files[8],
475+
);
476+
477+
$finder = new Finder();
478+
$finder->in($locations)->depth('< 10')->name('*.neon');
479+
480+
$expected = array(
481+
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
482+
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
483+
);
484+
485+
$this->assertIterator($expected, $finder);
486+
$this->assertIteratorInForeach($expected, $finder);
487+
}
462488
}

src/Symfony/Component/Finder/Tests/Fixtures/one/a

Whitespace-only changes.

src/Symfony/Component/Finder/Tests/Fixtures/one/b/c.neon

Whitespace-only changes.

src/Symfony/Component/Finder/Tests/Fixtures/one/b/d.neon

Whitespace-only changes.

src/Symfony/Component/Finder/Tests/Iterator/IteratorTestCase.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,41 @@ protected function assertOrderedIterator($expected, \Traversable $iterator)
2929

3030
$this->assertEquals($expected, array_values($values));
3131
}
32+
33+
/**
34+
* Same as IteratorTestCase::assertIterator with foreach usage
35+
*
36+
* @param array $expected
37+
* @param \Traversable $iterator
38+
*/
39+
protected function assertIteratorInForeach($expected, \Traversable $iterator)
40+
{
41+
$values = array();
42+
foreach ($iterator as $file) {
43+
$this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file);
44+
$values[] = $file->getPathname();
45+
}
46+
47+
sort($values);
48+
sort($expected);
49+
50+
$this->assertEquals($expected, array_values($values));
51+
}
52+
53+
/**
54+
* Same as IteratorTestCase::assertOrderedIterator with foreach usage
55+
*
56+
* @param array $expected
57+
* @param \Traversable $iterator
58+
*/
59+
protected function assertOrderedIteratorInForeach($expected, \Traversable $iterator)
60+
{
61+
$values = array();
62+
foreach ($iterator as $file) {
63+
$this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file);
64+
$values[] = $file->getPathname();
65+
}
66+
67+
$this->assertEquals($expected, array_values($values));
68+
}
3269
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy