Skip to content

Commit fe5db18

Browse files
committed
fix: replace {locale} with default locale in SampleURIGenerator
1 parent f6fabae commit fe5db18

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

system/Commands/Utilities/Routes/SampleURIGenerator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use CodeIgniter\Config\Services;
1515
use CodeIgniter\Router\RouteCollection;
16+
use Config\App;
1617

1718
/**
1819
* Generate a sample URI path from route key regex.
@@ -51,6 +52,14 @@ public function get(string $routeKey): string
5152
{
5253
$sampleUri = $routeKey;
5354

55+
if (strpos($routeKey, '{locale}') !== false) {
56+
$sampleUri = str_replace(
57+
'{locale}',
58+
config(App::class)->defaultLocale,
59+
$routeKey
60+
);
61+
}
62+
5463
foreach ($this->routes->getPlaceholders() as $placeholder => $regex) {
5564
$sample = $this->samples[$placeholder] ?? '::unknown::';
5665

tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public static function provideGet(): iterable
4040
'placeholder num' => ['shop/product/([0-9]+)', 'shop/product/123'],
4141
'placeholder segment' => ['shop/product/([^/]+)', 'shop/product/abc_123'],
4242
'placeholder any' => ['shop/product/(.*)', 'shop/product/123/abc'],
43+
'locale' => ['{locale}/home', 'en/home'],
44+
'locale segment' => ['{locale}/product/([^/]+)', 'en/product/abc_123'],
4345
'auto route' => ['home/index[/...]', 'home/index/1/2/3/4/5'],
4446
];
4547
}

0 commit comments

Comments
 (0)