Skip to content

Commit

Permalink
Do not mutate underlying values on redirect (#46281)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Feb 27, 2023
1 parent 864d2e5 commit 5e8f9b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(Request $request, UrlGenerator $url)

$parameters = $parameters->only(
$route->getCompiled()->getPathVariables()
)->toArray();
)->all();

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

Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Routing/RouteRedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Tests\Integration\Routing;

use Illuminate\Foundation\Auth\User;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Support\Facades\Route;
use Orchestra\Testbench\TestCase;

Expand Down Expand Up @@ -35,6 +37,19 @@ public static function routeRedirectDataSets()
];
}

public function testRouteRedirectWithExplicitRouteModelBinding()
{
$this->withoutExceptionHandling();
Route::middleware([SubstituteBindings::class])->group(function () {
Route::redirect('users/{user}', 'users/{user}/overview');
});
Route::bind('user', fn ($id) => (new User())->setAttribute('id', '999'));

$response = $this->get('users/1');

$response->assertRedirect('users/999/overview');
}

public function testToRouteHelper()
{
Route::get('to', function () {
Expand Down

0 comments on commit 5e8f9b0

Please sign in to comment.