Skip to content

Commit 0f5af86

Browse files
committed
merged branch jfsimon/issue-5851 (PR #5859)
This PR was merged into the master branch. Commits ------- 2817a47 [Finder] Fixed filename containing space bug in gnu adapter. 9bf7cb0 [Finder] Added filename containing space to tests. Discussion ---------- [Finder] Fixed filename containing space bug in gnu find adapter. Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes: #5851 `GNU find` adapter now uses `cut` instead of `awk`.
2 parents ba15925 + 2817a47 commit 0f5af86

8 files changed

+40
-37
lines changed

src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function searchInDirectory($dir)
8484
$this->buildDatesFiltering($find, $this->dates);
8585

8686
$useGrep = $this->shell->testCommand('grep') && $this->shell->testCommand('xargs');
87-
$useSort = is_int($this->sort) && $this->shell->testCommand('sort') && $this->shell->testCommand('awk');
87+
$useSort = is_int($this->sort) && $this->shell->testCommand('sort') && $this->shell->testCommand('cut');
8888

8989
if ($useGrep && ($this->contains || $this->notContains)) {
9090
$grep = $command->ins('grep');
@@ -286,8 +286,8 @@ private function buildSorting(Command $command, $sort)
286286
{
287287
switch ($sort) {
288288
case SortableIterator::SORT_BY_NAME:
289-
$format = null;
290-
break;
289+
$command->ins('sort')->add('| sort');
290+
return;
291291
case SortableIterator::SORT_BY_TYPE:
292292
$format = '%y';
293293
break;
@@ -306,6 +306,6 @@ private function buildSorting(Command $command, $sort)
306306

307307
$command->get('find')->add('-printf')->arg($format.' %h/%f\\n');
308308
$command->ins('sort')->add('| sort');
309-
$command->ins('awk')->add('| awk')->arg('{ print $'.(null === $format ? '1' : '2').' }');
309+
$command->ins('awk')->add('| cut')->arg('-d ')->arg('-f2-');
310310
}
311311
}

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public function testFiles($adapter)
5757
{
5858
$finder = $this->buildFinder($adapter);
5959
$this->assertSame($finder, $finder->files());
60-
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
60+
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
6161

6262
$finder = $this->buildFinder($adapter);
6363
$finder->files();
6464
$finder->directories();
6565
$finder->files();
66-
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
66+
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
6767
}
6868

6969
/**
@@ -73,11 +73,11 @@ public function testDepth($adapter)
7373
{
7474
$finder = $this->buildFinder($adapter);
7575
$this->assertSame($finder, $finder->depth('< 1'));
76-
$this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
76+
$this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
7777

7878
$finder = $this->buildFinder($adapter);
7979
$this->assertSame($finder, $finder->depth('<= 0'));
80-
$this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
80+
$this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
8181

8282
$finder = $this->buildFinder($adapter);
8383
$this->assertSame($finder, $finder->depth('>= 1'));
@@ -118,12 +118,12 @@ public function testNotName($adapter)
118118
{
119119
$finder = $this->buildFinder($adapter);
120120
$this->assertSame($finder, $finder->notName('*.php'));
121-
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
121+
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
122122

123123
$finder = $this->buildFinder($adapter);
124124
$finder->notName('*.php');
125125
$finder->notName('*.py');
126-
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->in(self::$tmpDir)->getIterator());
126+
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
127127

128128
$finder = $this->buildFinder($adapter);
129129
$finder->name('test.ph*');
@@ -172,7 +172,7 @@ public function testExclude($adapter)
172172
{
173173
$finder = $this->buildFinder($adapter);
174174
$this->assertSame($finder, $finder->exclude('foo'));
175-
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
175+
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
176176
}
177177

178178
/**
@@ -182,15 +182,15 @@ public function testIgnoreVCS($adapter)
182182
{
183183
$finder = $this->buildFinder($adapter);
184184
$this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
185-
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator());
185+
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
186186

187187
$finder = $this->buildFinder($adapter);
188188
$finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
189-
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator());
189+
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
190190

191191
$finder = $this->buildFinder($adapter);
192192
$this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
193-
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar')), $finder->in(self::$tmpDir)->getIterator());
193+
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
194194
}
195195

196196
/**
@@ -200,15 +200,15 @@ public function testIgnoreDotFiles($adapter)
200200
{
201201
$finder = $this->buildFinder($adapter);
202202
$this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
203-
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
203+
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
204204

205205
$finder = new Finder();
206206
$finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
207-
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
207+
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
208208

209209
$finder = $this->buildFinder($adapter);
210210
$this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
211-
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
211+
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
212212

213213
}
214214

@@ -219,7 +219,7 @@ public function testSortByName($adapter)
219219
{
220220
$finder = $this->buildFinder($adapter);
221221
$this->assertSame($finder, $finder->sortByName());
222-
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
222+
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
223223
}
224224

225225
/**
@@ -229,7 +229,7 @@ public function testSortByType($adapter)
229229
{
230230
$finder = $this->buildFinder($adapter);
231231
$this->assertSame($finder, $finder->sortByType());
232-
$this->assertIterator($this->toAbsolute(array('foo', 'toto', 'foo/bar.tmp', 'test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
232+
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'toto', 'foo/bar.tmp', 'test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
233233
}
234234

235235
/**
@@ -239,7 +239,7 @@ public function testSortByAccessedTime($adapter)
239239
{
240240
$finder = $this->buildFinder($adapter);
241241
$this->assertSame($finder, $finder->sortByAccessedTime());
242-
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo')), $finder->in(self::$tmpDir)->getIterator());
242+
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
243243
}
244244

245245
/**
@@ -249,7 +249,7 @@ public function testSortByChangedTime($adapter)
249249
{
250250
$finder = $this->buildFinder($adapter);
251251
$this->assertSame($finder, $finder->sortByChangedTime());
252-
$this->assertIterator($this->toAbsolute(array('toto', 'test.py', 'test.php', 'foo/bar.tmp', 'foo')), $finder->in(self::$tmpDir)->getIterator());
252+
$this->assertIterator($this->toAbsolute(array('toto', 'test.py', 'test.php', 'foo/bar.tmp', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
253253
}
254254

255255
/**
@@ -259,7 +259,7 @@ public function testSortByModifiedTime($adapter)
259259
{
260260
$finder = $this->buildFinder($adapter);
261261
$this->assertSame($finder, $finder->sortByModifiedTime());
262-
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo')), $finder->in(self::$tmpDir)->getIterator());
262+
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
263263
}
264264

265265
/**
@@ -269,7 +269,7 @@ public function testSort($adapter)
269269
{
270270
$finder = $this->buildFinder($adapter);
271271
$this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealpath(), $b->getRealpath()); }));
272-
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
272+
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
273273
}
274274

275275
/**
@@ -293,7 +293,7 @@ public function testFollowLinks($adapter)
293293

294294
$finder = $this->buildFinder($adapter);
295295
$this->assertSame($finder, $finder->followLinks());
296-
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
296+
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
297297
}
298298

299299
/**
@@ -366,7 +366,7 @@ public function testRelativePath($adapter)
366366
$paths[] = $file->getRelativePath();
367367
}
368368

369-
$ref = array("", "", "", "", "foo");
369+
$ref = array("", "", "", "", "foo", "");
370370

371371
sort($ref);
372372
sort($paths);
@@ -389,7 +389,7 @@ public function testRelativePathname($adapter)
389389
$paths[] = $file->getRelativePathname();
390390
}
391391

392-
$ref = array("test.php", "toto", "test.py", "foo", "foo".DIRECTORY_SEPARATOR."bar.tmp");
392+
$ref = array("test.php", "toto", "test.py", "foo", "foo".DIRECTORY_SEPARATOR."bar.tmp", "foo bar");
393393

394394
sort($paths);
395395
sort($ref);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function testAccept($size, $expected)
3131
public function getAcceptData()
3232
{
3333
return array(
34-
array(array(new DateComparator('since 20 years ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar')),
35-
array(array(new DateComparator('since 2 months ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar')),
34+
array(array(new DateComparator('since 20 years ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/foo bar')),
35+
array(array(new DateComparator('since 2 months ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/foo bar')),
3636
array(array(new DateComparator('until last month')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.foo')),
3737
);
3838
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function testAccept($minDepth, $maxDepth, $expected)
3434
public function getAcceptData()
3535
{
3636
return array(
37-
array(0, 0, array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.bar'))),
38-
array(0, 1, array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.bar'))),
37+
array(0, 0, array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.bar'), $this->getAbsolutePath('/foo bar'))),
38+
array(0, 1, array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.bar'), $this->getAbsolutePath('/foo bar'))),
3939
array(2, INF, array()),
4040
array(1, INF, array($this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/.foo/.bar'))),
4141
array(1, 1, array($this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/.foo/.bar'))),

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public function getAcceptData()
4040
$tmpDir.DIRECTORY_SEPARATOR.'.git',
4141
$tmpDir.DIRECTORY_SEPARATOR.'test.py',
4242
$tmpDir.DIRECTORY_SEPARATOR.'test.php',
43-
$tmpDir.DIRECTORY_SEPARATOR.'toto'
43+
$tmpDir.DIRECTORY_SEPARATOR.'toto',
44+
$tmpDir.DIRECTORY_SEPARATOR.'foo bar',
4445
)),
4546
array(array('fo'), array(
4647
$tmpDir.DIRECTORY_SEPARATOR.'.bar',
@@ -51,7 +52,8 @@ public function getAcceptData()
5152
$tmpDir.DIRECTORY_SEPARATOR.'foo',
5253
$tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp',
5354
$tmpDir.DIRECTORY_SEPARATOR.'test.php',
54-
$tmpDir.DIRECTORY_SEPARATOR.'toto'
55+
$tmpDir.DIRECTORY_SEPARATOR.'toto',
56+
$tmpDir.DIRECTORY_SEPARATOR.'foo bar',
5557
)),
5658
);
5759
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testAccept($mode, $expected)
3030
public function getAcceptData()
3131
{
3232
return array(
33-
array(FileTypeFilterIterator::ONLY_FILES, array(sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/.bar')),
33+
array(FileTypeFilterIterator::ONLY_FILES, array(sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/foo bar')),
3434
array(FileTypeFilterIterator::ONLY_DIRECTORIES, array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.foo')),
3535
);
3636
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public static function setUpBeforeClass()
2727
$tmpDir.'/foo/',
2828
$tmpDir.'/foo/bar.tmp',
2929
$tmpDir.'/test.php',
30-
$tmpDir.'/toto/'
30+
$tmpDir.'/toto/',
31+
$tmpDir.'/foo bar',
3132
);
3233

3334
if (is_dir($tmpDir)) {

0 commit comments

Comments
 (0)