Skip to content

Commit 039bb47

Browse files
committed
bug #987 Fixing problem where rootDir is ".", which strips all dots from the filename (weaverryan)
This PR was merged into the 1.x branch. Discussion ---------- Fixing problem where rootDir is ".", which strips all dots from the filename Fixes symfony/recipes#1120 In a normal siutation, `$rootDir` is `.`. The intention of this code is to strip the "rootDir" from the START of the `$file` path, so that we are left with only the relative path. The `.` + `str_replace()` was too greedy, and was causing things like `docker-composeryaml`. The test uses an absolute root dir, and replicating the `.` would be tricky. But I tested this locally and the fix works. Cheers! Commits ------- 55d088e Fixinb problem where rootDir is ".", which strips all dots from the filename
2 parents 49059a1 + 55d088e commit 039bb47

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Configurator/DockerComposeConfigurator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ private function getContentsAfterApplyingRecipe(string $rootDir, Recipe $recipe,
332332

333333
$updatedContents = [];
334334
foreach ($files as $file) {
335-
$localPath = ltrim(str_replace($rootDir, '', $file), '/\\');
335+
$localPath = $file;
336+
if (0 === strpos($file, $rootDir)) {
337+
$localPath = substr($file, \strlen($rootDir) + 1);
338+
}
339+
$localPath = ltrim($localPath, '/\\');
336340
$updatedContents[$localPath] = file_exists($file) ? file_get_contents($file) : null;
337341
}
338342

0 commit comments

Comments
 (0)