diff --git a/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php b/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php index 7f2a52fbcd810..4d73b32c34d20 100644 --- a/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php @@ -216,7 +216,7 @@ private function buildPathsFiltering(Command $command, $dir, array $paths, $not // Fixes 'not search' regex problems. if ($expr->isRegex()) { $regex = $expr->getRegex(); - $regex->prepend($regex->hasStartFlag() ? $dir.DIRECTORY_SEPARATOR : '.*')->setEndJoker(!$regex->hasEndFlag()); + $regex->prepend($regex->hasStartFlag() ? preg_quote($dir).DIRECTORY_SEPARATOR : '.*')->setEndJoker(!$regex->hasEndFlag()); } else { $expr->prepend('*')->append('*'); } @@ -247,7 +247,7 @@ private function buildSizesFiltering(Command $command, array $sizes) $command->add('-size -'.($size->getTarget() + 1).'c'); break; case '>=': - $command->add('-size +'. ($size->getTarget() - 1).'c'); + $command->add('-size +'.($size->getTarget() - 1).'c'); break; case '>': $command->add('-size +'.$size->getTarget().'c'); diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index 598821d24f521..924c67bd897c0 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -569,6 +569,20 @@ public function testIteratorKeys(Adapter\AdapterInterface $adapter) } } + /** + * @dataProvider getAdaptersTestData + */ + public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag(Adapter\AdapterInterface $adapter) + { + $finder = $this->buildFinder($adapter); + $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'r+e.g?e*x[c]a(r)s') + ->path('/^dir/'); + + $expected = array('r+e.g?e*x[c]a(r)s'.DIRECTORY_SEPARATOR.'dir', + 'r+e.g?e*x[c]a(r)s'.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'bar.dat',); + $this->assertIterator($this->toAbsoluteFixtures($expected), $finder); + } + public function testAdaptersOrdering() { $finder = Finder::create() @@ -673,7 +687,7 @@ public function getTestPathData() $tests = array( array('', '', array()), array('/^A\/B\/C/', '/C$/', - array('A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat') + array('A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat'), ), array('/^A\/B/', 'foobar', array( @@ -681,7 +695,7 @@ public function getTestPathData() 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C', 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat', 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat', - ) + ), ), array('A/B/C', 'foobar', array( @@ -689,7 +703,7 @@ public function getTestPathData() 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat.copy', - ) + ), ), array('A/B', 'foobar', array( @@ -703,12 +717,12 @@ public function getTestPathData() 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat.copy', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat.copy', - ) + ), ), array('/^with space\//', 'foobar', array( 'with space'.DIRECTORY_SEPARATOR.'foo.txt', - ) + ), ), ); @@ -808,7 +822,7 @@ private function getValidAdapters() array( new Adapter\BsdFindAdapter(), new Adapter\GnuFindAdapter(), - new Adapter\PhpAdapter() + new Adapter\PhpAdapter(), ), function (Adapter\AdapterInterface $adapter) { return $adapter->isSupported(); diff --git a/src/Symfony/Component/Finder/Tests/Fixtures/r+e.g?e*x[c]a(r)s/dir/bar.dat b/src/Symfony/Component/Finder/Tests/Fixtures/r+e.g?e*x[c]a(r)s/dir/bar.dat new file mode 100644 index 0000000000000..e69de29bb2d1d