Laravel Version
13.5.0
PHP Version
8.5
Database Driver & Version
No response
Description
When using a filesystem with the local driver and the setting serve = true, files with urlencoded characters on them cannot be served because the url gets decoded before being passed to the Filesystem's ServeFile class.
See following test that fails when it shouldn't.
#[WithConfig('filesystems.disks.local.serve', true)]
class ServeFileTest extends TestCase
{
// ...
public function testServingFileWithUrlEncodedCharactersWorks()
{
Storage::put('serve%20file%20test.txt', 'Hello World');
$url = Storage::temporaryUrl('serve%20file%20test.txt', Carbon::now()->addMinutes(1));
$response = $this->get($url);
$response->assertOk();
}
}
On src/Illuminate/Filesystem/FilesystemServiceProvider.php, when creating the route for serving the locally stored files, the $path variable that's passed to the ServeFile class, it's already urldecoded, so the file can never be found.
Steps To Reproduce
- Store a file with urlencoded characters (like
%20) on it on a filesystem with a local driver.
- Try to access it through HTTP on the url returned by
Storage::url($filename).
- Get a 404 even though the file exists.
Laravel Version
13.5.0
PHP Version
8.5
Database Driver & Version
No response
Description
When using a filesystem with the local driver and the setting
serve = true, files with urlencoded characters on them cannot be served because the url gets decoded before being passed to the Filesystem'sServeFileclass.See following test that fails when it shouldn't.
On
src/Illuminate/Filesystem/FilesystemServiceProvider.php, when creating the route for serving the locally stored files, the$pathvariable that's passed to theServeFileclass, it's already urldecoded, so the file can never be found.Steps To Reproduce
%20) on it on a filesystem with a local driver.Storage::url($filename).