From b1a951babbbcd2a24a740c8778e64d1bd75a287c Mon Sep 17 00:00:00 2001 From: Franco Gilio Date: Tue, 3 Jan 2017 10:57:22 -0300 Subject: [PATCH] [5.3] Stricter comparison when replacing URL for LocalAdapter (#17097) I have an edgy case with a directory name that starts with string `public`, like this: - `/storage/app/public/public.../files` So this was triggering the ternary on line `298` and the resulting URL was broken. Here is a real example: - Upload public path for LocalAdapter is `publicala/logo.svg`, full path from project root being `/storage/app/public/publicala/logo.svg`. - Generated URL was `https://laravelapp.dev/storageala/logo.svg` With this litle patch the generated URL is `https://laravelapp.dev/storage/publicala/logo.svg` This would also be useful for directory names ending with string `public` --- src/Illuminate/Filesystem/FilesystemAdapter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index b42a47b4d1f2..7c114923d2bc 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -295,8 +295,8 @@ public function url($path) $path = '/storage/'.$path; - return Str::contains($path, '/storage/public') ? - Str::replaceFirst('/public', '', $path) : $path; + return Str::contains($path, '/storage/public/') ? + Str::replaceFirst('/public/', '/', $path) : $path; } else { throw new RuntimeException('This driver does not support retrieving URLs.'); }