Skip to content

Commit

Permalink
consistently use str_replace to unify directory separators
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Aug 25, 2015
1 parent cca29d8 commit b9760ef
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
Expand Up @@ -26,7 +26,7 @@ class TemplateFilenameParser implements TemplateNameParserInterface
*/
public function parse($file)
{
$parts = explode('/', strtr($file, '\\', '/'));
$parts = explode('/', str_replace('\\', '/', $file));

$elements = explode('.', array_pop($parts));
if (3 > count($elements)) {
Expand Down
Expand Up @@ -50,7 +50,7 @@ public function parse($name)
}

// normalize name
$name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')));
$name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', str_replace('\\', '/', $name)));

if (false !== strpos($name, '..')) {
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
Expand Down
Expand Up @@ -140,10 +140,10 @@ public function testCreateMapFinderSupport()
protected function assertEqualsNormalized($expected, $actual, $message = null)
{
foreach ($expected as $ns => $path) {
$expected[$ns] = strtr($path, '\\', '/');
$expected[$ns] = str_replace('\\', '/', $path);
}
foreach ($actual as $ns => $path) {
$actual[$ns] = strtr($path, '\\', '/');
$actual[$ns] = str_replace('\\', '/', $path);
}
$this->assertEquals($expected, $actual, $message);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -313,8 +313,8 @@ public function makePathRelative($endPath, $startPath)
{
// Normalize separators on Windows
if ('\\' === DIRECTORY_SEPARATOR) {
$endPath = strtr($endPath, '\\', '/');
$startPath = strtr($startPath, '\\', '/');
$endPath = str_replace('\\', '/', $endPath);
$startPath = str_replace('\\', '/', $startPath);
}

// Split the paths into arrays
Expand Down
Expand Up @@ -44,7 +44,7 @@ public function __construct(\Iterator $iterator, array $directories)
public function accept()
{
$path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
$path = strtr($path, '\\', '/');
$path = str_replace('\\', '/', $path);
foreach ($this->patterns as $pattern) {
if (preg_match($pattern, $path)) {
return false;
Expand Down
Expand Up @@ -29,7 +29,7 @@ public function accept()
$filename = $this->current()->getRelativePathname();

if ('\\' === DIRECTORY_SEPARATOR) {
$filename = strtr($filename, '\\', '/');
$filename = str_replace('\\', '/', $filename);
}

// should at least not match one rule to exclude
Expand Down

0 comments on commit b9760ef

Please sign in to comment.