Skip to content

Commit bb162d5

Browse files
committed
Handle capitalized route parameters with Route::localizedUrl()
1 parent 25365bf commit bb162d5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/LocalizedUrlGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ protected function updateLocaleInSlugs(array $slugs, $locale)
306306
*/
307307
protected function extractQueryParameters($uri, $parameters)
308308
{
309-
preg_match_all('/{([a-z_.-]+\??)}/', $uri, $matches);
309+
preg_match_all('/{([a-zA-Z_.-]+\??)}/', $uri, $matches);
310310
$paramKeys = $matches[1] ?? [];
311311

312312
$slugs = [];
@@ -347,7 +347,7 @@ protected function replaceParameters($uri, $parameters)
347347
$uri = str_replace($placeholder, $value, $uri);
348348
}
349349

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

352352
return $uri;
353353
}

tests/Unit/Macros/LocalizedUrlMacroTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,30 @@ public function it_allows_optional_parameters_with_unnamed_routes()
771771
], $response->original);
772772
}
773773

774+
/** @test */
775+
public function it_handles_capitalized_parameter_names()
776+
{
777+
$this->withoutExceptionHandling();
778+
$this->setSupportedLocales(['en', 'nl']);
779+
780+
Route::get('route/{slugWithCaps}/{optionalSlugWithCaps?}', function () {
781+
return [
782+
'current' => Route::localizedUrl(null, ['another-slug']),
783+
'en' => Route::localizedUrl('en', ['another-slug']),
784+
'nl' => Route::localizedUrl('nl', ['another-slug']),
785+
];
786+
});
787+
788+
$response = $this->call('GET', '/route/some-slug');
789+
$response->assertOk();
790+
$this->assertEquals([
791+
'current' => url('/route/another-slug'),
792+
'en' => url('/route/another-slug'),
793+
'nl' => url('/route/another-slug'),
794+
], $response->original);
795+
796+
}
797+
774798
/** @test */
775799
public function it_returns_a_url_with_translated_slugs_for_named_routes()
776800
{

0 commit comments

Comments
 (0)