From 445229976f561c4e968875a7d9caa083d076f016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 22 Jun 2024 19:47:55 +0200 Subject: [PATCH] Allow locales like de_DE in removeLocaleFromPath function Related to issue #563 --- src/Twig/UserExtension.php | 2 +- tests/Twig/UserExtensionTest.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Twig/UserExtension.php b/src/Twig/UserExtension.php index 93ea57be..5045257a 100644 --- a/src/Twig/UserExtension.php +++ b/src/Twig/UserExtension.php @@ -127,7 +127,7 @@ final class UserExtension extends AbstractExtension public function removeLocaleFromPath(string $path): string { //Ensure the path has the correct format - if (!preg_match('/^\/\w{2}\//', $path)) { + if (!preg_match('/^\/\w{2}(?:_\w{2})?\//', $path)) { throw new \InvalidArgumentException('The given path is not a localized path!'); } diff --git a/tests/Twig/UserExtensionTest.php b/tests/Twig/UserExtensionTest.php index 1344bbc5..ea024bda 100644 --- a/tests/Twig/UserExtensionTest.php +++ b/tests/Twig/UserExtensionTest.php @@ -36,16 +36,18 @@ class UserExtensionTest extends WebTestCase $this->service = self::getContainer()->get(UserExtension::class); } - public function removeeLocaleFromPathDataSet(): ?\Generator + public function removeLocaleFromPathDataSet(): ?\Generator { yield ['/', '/de/']; yield ['/test', '/de/test']; yield ['/test/foo', '/en/test/foo']; yield ['/test/foo/bar?param1=val1¶m2=val2', '/en/test/foo/bar?param1=val1¶m2=val2']; + //Allow de_DE + yield ['/test/foo/bar?param1=val1¶m2=val2', '/de_DE/test/foo/bar?param1=val1¶m2=val2']; } /** - * @dataProvider removeeLocaleFromPathDataSet + * @dataProvider removeLocaleFromPathDataSet */ public function testRemoveLocaleFromPath(string $expected, string $input): void {