Skip to content

Commit

Permalink
Handle capitalized route parameters with Route::localizedUrl()
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvermeyen committed Jan 17, 2020
1 parent 25365bf commit bb162d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/LocalizedUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ protected function updateLocaleInSlugs(array $slugs, $locale)
*/
protected function extractQueryParameters($uri, $parameters)
{
preg_match_all('/{([a-z_.-]+\??)}/', $uri, $matches);
preg_match_all('/{([a-zA-Z_.-]+\??)}/', $uri, $matches);
$paramKeys = $matches[1] ?? [];

$slugs = [];
Expand Down Expand Up @@ -347,7 +347,7 @@ protected function replaceParameters($uri, $parameters)
$uri = str_replace($placeholder, $value, $uri);
}

$uri = preg_replace('/{[a-z_.-]+\?}/', '', $uri);
$uri = preg_replace('/{[a-zA-Z_.-]+\?}/', '', $uri);

return $uri;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Macros/LocalizedUrlMacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,30 @@ public function it_allows_optional_parameters_with_unnamed_routes()
], $response->original);
}

/** @test */
public function it_handles_capitalized_parameter_names()
{
$this->withoutExceptionHandling();
$this->setSupportedLocales(['en', 'nl']);

Route::get('route/{slugWithCaps}/{optionalSlugWithCaps?}', function () {
return [
'current' => Route::localizedUrl(null, ['another-slug']),
'en' => Route::localizedUrl('en', ['another-slug']),
'nl' => Route::localizedUrl('nl', ['another-slug']),
];
});

$response = $this->call('GET', '/route/some-slug');
$response->assertOk();
$this->assertEquals([
'current' => url('/route/another-slug'),
'en' => url('/route/another-slug'),
'nl' => url('/route/another-slug'),
], $response->original);

}

/** @test */
public function it_returns_a_url_with_translated_slugs_for_named_routes()
{
Expand Down

0 comments on commit bb162d5

Please sign in to comment.