Merge branch '5.2' into 5.x

* 5.2:
  [TwigBridge] Install symfony/intl to run tests on Travis
  [Translation] Make `name` attribute optional in xliff2
  [Security] #[CurrentUser] argument should resolve to null when it is anonymous
This commit is contained in:
Robin Chalas 2021-02-25 14:42:49 +01:00
commit adbb34115c
6 changed files with 26 additions and 10 deletions

View File

@ -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",

View File

@ -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;
}

View File

@ -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);

View File

@ -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

View File

@ -43,6 +43,7 @@ class XliffFileDumperTest extends TestCase
'foo' => 'bar',
'key' => '',
'key.with.cdata' => '<source> & <target>',
'translation.key.that.is.longer.than.eighty.characters.should.not.have.name.attribute' => 'value',
]);
$catalogue->setMetadata('key', ['target-attributes' => ['order' => 1]]);

View File

@ -19,5 +19,11 @@
<target><![CDATA[<source> & <target>]]></target>
</segment>
</unit>
<unit id="aF1tx51">
<segment>
<source>translation.key.that.is.longer.than.eighty.characters.should.not.have.name.attribute</source>
<target>value</target>
</segment>
</unit>
</file>
</xliff>