Skip to content

Commit

Permalink
bug #987 Fixing problem where rootDir is ".", which strips all dots f…
Browse files Browse the repository at this point in the history
…rom 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
  • Loading branch information
fabpot committed Aug 2, 2023
2 parents 49059a1 + 55d088e commit 039bb47
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Configurator/DockerComposeConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ private function getContentsAfterApplyingRecipe(string $rootDir, Recipe $recipe,

$updatedContents = [];
foreach ($files as $file) {
$localPath = ltrim(str_replace($rootDir, '', $file), '/\\');
$localPath = $file;
if (0 === strpos($file, $rootDir)) {
$localPath = substr($file, \strlen($rootDir) + 1);
}
$localPath = ltrim($localPath, '/\\');
$updatedContents[$localPath] = file_exists($file) ? file_get_contents($file) : null;
}

Expand Down

0 comments on commit 039bb47

Please sign in to comment.