Skip to content

Commit 5e8f9b0

Browse files
authored
Do not mutate underlying values on redirect (#46281)
1 parent 864d2e5 commit 5e8f9b0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Illuminate/Routing/RedirectController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __invoke(Request $request, UrlGenerator $url)
3131

3232
$parameters = $parameters->only(
3333
$route->getCompiled()->getPathVariables()
34-
)->toArray();
34+
)->all();
3535

3636
$url = $url->toRoute($route, $parameters, false);
3737

tests/Integration/Routing/RouteRedirectTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Illuminate\Tests\Integration\Routing;
44

5+
use Illuminate\Foundation\Auth\User;
6+
use Illuminate\Routing\Middleware\SubstituteBindings;
57
use Illuminate\Support\Facades\Route;
68
use Orchestra\Testbench\TestCase;
79

@@ -35,6 +37,19 @@ public static function routeRedirectDataSets()
3537
];
3638
}
3739

40+
public function testRouteRedirectWithExplicitRouteModelBinding()
41+
{
42+
$this->withoutExceptionHandling();
43+
Route::middleware([SubstituteBindings::class])->group(function () {
44+
Route::redirect('users/{user}', 'users/{user}/overview');
45+
});
46+
Route::bind('user', fn ($id) => (new User())->setAttribute('id', '999'));
47+
48+
$response = $this->get('users/1');
49+
50+
$response->assertRedirect('users/999/overview');
51+
}
52+
3853
public function testToRouteHelper()
3954
{
4055
Route::get('to', function () {

0 commit comments

Comments
 (0)