Skip to content

Commit

Permalink
[5.3] Stricter comparison when replacing URL for LocalAdapter (#17097)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
fgilio authored and taylorotwell committed Jan 3, 2017
1 parent 5dd17b6 commit b1a951b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down

0 comments on commit b1a951b

Please sign in to comment.