diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index dcda6c8079..44fb474553 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -30,6 +30,7 @@ "symfony/form": "^5.3", "symfony/http-foundation": "^4.4|^5.0", "symfony/http-kernel": "^4.4|^5.0", + "symfony/intl": "^4.4|^5.0", "symfony/mime": "^5.2", "symfony/polyfill-intl-icu": "~1.0", "symfony/property-info": "^4.4|^5.1", diff --git a/src/Symfony/Component/Security/Http/Controller/UserValueResolver.php b/src/Symfony/Component/Security/Http/Controller/UserValueResolver.php index 396b430ac9..4b469edf8b 100644 --- a/src/Symfony/Component/Security/Http/Controller/UserValueResolver.php +++ b/src/Symfony/Component/Security/Http/Controller/UserValueResolver.php @@ -35,12 +35,9 @@ final class UserValueResolver implements ArgumentValueResolverInterface public function supports(Request $request, ArgumentMetadata $argument): bool { - if ($argument->getAttribute() instanceof CurrentUser) { - return true; - } - - // only security user implementations are supported - if (UserInterface::class !== $argument->getType()) { + // with the attribute, the type can be any UserInterface implementation + // otherwise, the type must be UserInterface + if (UserInterface::class !== $argument->getType() && !$argument->getAttribute() instanceof CurrentUser) { return false; } diff --git a/src/Symfony/Component/Security/Http/Tests/Controller/UserValueResolverTest.php b/src/Symfony/Component/Security/Http/Tests/Controller/UserValueResolverTest.php index b95aa465c3..ca3197e5e4 100644 --- a/src/Symfony/Component/Security/Http/Tests/Controller/UserValueResolverTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Controller/UserValueResolverTest.php @@ -83,6 +83,17 @@ class UserValueResolverTest extends TestCase $this->assertSame([$user], iterator_to_array($resolver->resolve(Request::create('/'), $metadata))); } + public function testResolveWithAttributeAndNoUser() + { + $tokenStorage = new TokenStorage(); + $tokenStorage->setToken(new UsernamePasswordToken('username', 'password', 'provider')); + + $resolver = new UserValueResolver($tokenStorage); + $metadata = new ArgumentMetadata('foo', null, false, false, null, false, new CurrentUser()); + + $this->assertFalse($resolver->supports(Request::create('/'), $metadata)); + } + public function testIntegration() { $user = $this->createMock(UserInterface::class); diff --git a/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php b/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php index 5b878e3691..7d0a4464e1 100644 --- a/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/XliffFileDumper.php @@ -150,11 +150,11 @@ class XliffFileDumper extends FileDumper foreach ($messages->all($domain) as $source => $target) { $translation = $dom->createElement('unit'); $translation->setAttribute('id', strtr(substr(base64_encode(hash('sha256', $source, true)), 0, 7), '/+', '._')); - $name = $source; - if (\strlen($source) > 80) { - $name = substr(md5($source), -7); + + if (\strlen($source) <= 80) { + $translation->setAttribute('name', $source); } - $translation->setAttribute('name', $name); + $metadata = $messages->getMetadata($source, $domain); // Add notes section diff --git a/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php index 6377132f70..cb995553b5 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php @@ -43,6 +43,7 @@ class XliffFileDumperTest extends TestCase 'foo' => 'bar', 'key' => '', 'key.with.cdata' => ' & ', + 'translation.key.that.is.longer.than.eighty.characters.should.not.have.name.attribute' => 'value', ]); $catalogue->setMetadata('key', ['target-attributes' => ['order' => 1]]); diff --git a/src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf b/src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf index efa69b27ff..ccc5ef7a72 100644 --- a/src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf +++ b/src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf @@ -19,5 +19,11 @@ & ]]> + + + translation.key.that.is.longer.than.eighty.characters.should.not.have.name.attribute + value + +