Skip to content

[Filesystem] makePathRelative with existing files, remove ending / #47424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 7.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ public function makePathRelative(string $endPath, string $startPath): string
// Construct $endPath from traversing to the common path, then to the remaining $endPath
$relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : '');

// Remove ending "/" if $endPath points to existing file
if (file_exists($endPath) && !is_dir($endPath) && str_ends_with($relativePath, '/')) {
$relativePath = rtrim($relativePath, '/');
}

return '' === $relativePath ? './' : $relativePath;
}

Expand Down Expand Up @@ -669,7 +674,6 @@ public function dumpFile(string $filename, $content)
* Appends content to an existing file.
*
* @param string|resource $content The content to append
* @param bool $lock Whether the file should be locked when writing to it
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed by phpcs with Symfony standard.

*
* @throws IOException If the file is not writable
*/
Expand Down