Skip to content

Commit

Permalink
Fix error pages in multilang
Browse files Browse the repository at this point in the history
Fixes #4834
  • Loading branch information
distantnative committed Sep 12, 2024
1 parent f724075 commit fc4e8fd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Cms/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Kirby\Exception\LogicException;
use Kirby\Exception\PermissionException;
use Kirby\Filesystem\F;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Locale;
use Kirby\Toolkit\Str;
use Throwable;
Expand Down Expand Up @@ -213,7 +214,7 @@ public static function create(array $props): static
*/
public function delete(): bool
{
$kirby = App::instance();
$kirby = $this->kirby();
$user = $kirby->user();
$code = $this->code();

Expand Down Expand Up @@ -382,7 +383,20 @@ public function pattern(): string
$path = $this->path();

if (empty($path) === true) {
return '(:all)';
$pattern = '(:all)';

// match anything except paths that begin with the prefix
// of any other language
$languages = $this->kirby()->languages()->not($this)->values(
fn ($language) => $language->path()
);

if (count($languages) > 0) {
$pattern = '^(?!(?:' . A::join($languages, '|') . ')\/)' . $pattern;
}


return $pattern;
}

return $path . '/(:all?)';
Expand Down
27 changes: 27 additions & 0 deletions tests/Cms/Languages/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,33 @@ public function testPattern($input, $expected)
$this->assertSame($expected, $language->pattern());
}

/**
* @covers ::pattern
*/
public function testPatternWithNoPathPrefixButOtherLanguages()
{
$app = $this->app->clone([
'languages' => [
[
'code' => 'en',
'name' => 'English',
'default' => true,
'url' => '/'
],
[
'code' => 'de',
'name' => 'Deutsch',
],
[
'code' => 'fr',
'name' => 'Frances',
]
]
]);

$this->assertSame('^(?!(?:de|fr)\/)(:all)', $app->language('en')->pattern());
}

/**
* @covers ::root
*/
Expand Down

0 comments on commit fc4e8fd

Please sign in to comment.