Skip to content

Commit 4735e56

Browse files
BenoitLevequefabpot
authored andcommitted
Fix "absolute path" when we look to the cache directory
We should get __DIR__ instead of __DIR__ . '/.'
1 parent 309046a commit 4735e56

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,15 @@ private function removeAbsolutePathsFromContainer($content)
748748
$filesystem = new Filesystem();
749749

750750
return preg_replace_callback("{'([^']*)(".preg_quote($rootDir)."[^']*)'}", function ($match) use ($filesystem, $cacheDir) {
751-
$prefix = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__.'/" : "__DIR__.'/";
751+
$prefix = isset($match[1]) && $match[1] ? "'$match[1]'.__DIR__" : "__DIR__";
752752

753-
return $prefix.rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/')."'";
753+
$relativePath = rtrim($filesystem->makePathRelative($match[2], $cacheDir), '/');
754+
755+
if ($relativePath === '.') {
756+
return $prefix;
757+
}
758+
759+
return $prefix . ".'/" . $relativePath . "'";
754760
}, $content);
755761
}
756762

src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withAbsolutePaths.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'ROOT_DIR/app/cache/dev/foo'
22
'ROOT_DIR/app/cache/foo'
33
'ROOT_DIR/foo/bar.php'
4+
'ROOT_DIR/app/cache/dev'
45

56
'/some/where/else/foo'
67

src/Symfony/Component/HttpKernel/Tests/Fixtures/DumpedContainers/app/cache/dev/withoutAbsolutePaths.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__DIR__.'/foo'
22
__DIR__.'/../foo'
33
__DIR__.'/../../../foo/bar.php'
4+
__DIR__
45

56
'/some/where/else/foo'
67

0 commit comments

Comments
 (0)