merged branch havvg/hotfix/finder-spaces-in-dir (PR #7302)

This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #7302).

Commits
-------

3f3cf0c fix xargs pipe to work with spaces in dir names

Discussion
----------

[Finder] fix xargs pipe to work with spaces in dir names

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

.. otherwise grep fails:

````
grep: : No such file or directory
grep: /Users/havvg/Web: No such file or directory
grep: Development/symfony2/src/Symfony/Component/Finder/Tests/Fixtures/dolor.txt: No such file or directory
```
This commit is contained in:
Fabien Potencier 2013-03-08 17:54:58 +01:00
commit b7a85e0093
4 changed files with 13 additions and 4 deletions

View File

@ -92,10 +92,12 @@ class BsdFindAdapter extends AbstractFindAdapter
// todo: avoid forking process for each $pattern by using multiple -e options
$command
->add('| grep -v \'^$\'')
->add('| xargs grep -I')
->add('| xargs -I{} grep -I')
->add($expr->isCaseSensitive() ? null : '-i')
->add($not ? '-L' : '-l')
->add('-Ee')->arg($expr->renderPattern());
->add('-Ee')->arg($expr->renderPattern())
->add('{}')
;
}
}
}

View File

@ -93,10 +93,12 @@ class GnuFindAdapter extends AbstractFindAdapter
// todo: avoid forking process for each $pattern by using multiple -e options
$command
->add('| xargs -r grep -I')
->add('| xargs -I{} -r grep -I')
->add($expr->isCaseSensitive() ? null : '-i')
->add($not ? '-L' : '-l')
->add('-Ee')->arg($expr->renderPattern());
->add('-Ee')->arg($expr->renderPattern())
->add('{}')
;
}
}
}

View File

@ -707,6 +707,11 @@ class FinderTest extends Iterator\RealIteratorTestCase
'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',
)
),
);
return $this->buildTestData($tests);