Allow locales like de_DE in removeLocaleFromPath function

Related to issue #563
This commit is contained in:
Jan Böhmer 2024-06-22 19:47:55 +02:00
parent eb02404d49
commit 445229976f
2 changed files with 5 additions and 3 deletions

View file

@ -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!');
}

View file

@ -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&param2=val2', '/en/test/foo/bar?param1=val1&param2=val2'];
//Allow de_DE
yield ['/test/foo/bar?param1=val1&param2=val2', '/de_DE/test/foo/bar?param1=val1&param2=val2'];
}
/**
* @dataProvider removeeLocaleFromPathDataSet
* @dataProvider removeLocaleFromPathDataSet
*/
public function testRemoveLocaleFromPath(string $expected, string $input): void
{