8000 Merge branch '5.2' into 5.x · symfony/symfony@adbb341 · GitHub
[go: up one dir, main page]

Skip to content

Commit adbb341

Browse files
committed
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
2 parents d54a122 + f4c9fee commit adbb341

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"symfony/form": "^5.3",
3131
"symfony/http-foundation": "^4.4|^5.0",
3232
"symfony/http-kernel": "^4.4|^5.0",
33+
"symfony/intl": "^4.4|^5.0",
3334
"symfony/mime": "^5.2",
3435
"symfony/polyfill-intl-icu": "~1.0",
3536
"symfony/property-info": "^4.4|^5.1",

src/Symfony/Component/Security/Http/Controller/UserValueResolver.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ public function __construct(TokenStorageInterface $tokenStorage)
3535

3636
public function supports(Request $request, ArgumentMetadata $argument): bool
3737
{
38-
if ($argument->getAttribute() instanceof CurrentUser) {
39-
return true;
40-
}
41-
42-
// only security user implementations are supported
43-
if (UserInterface::class !== $argument->getType()) {
38+
// with the attribute, the type can be any UserInterface implementation
39+
// otherwise, the type must be UserInterface
40+
if (UserInterface::class !== $argument->getType() && !$argument->getAttribute() instanceof CurrentUser) {
4441
return false;
4542
}
4643

src/Symfony/Component/Security/Http/Tests/Controller/UserValueResolverTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ public function testResolveWithAttribute()
8383
$this->assertSame([$user], iterator_to_array($resolver->resolve(Request::create('/'), $metadata)));
8484
}
8585

86+
public function testResolveWithAttributeAndNoUser()
87+
{
88+
$tokenStorage = new TokenStorage();
89+
$tokenStorage->setToken(new UsernamePasswordToken('username', 'password', 'provider'));
90+
91+
$resolver = new UserValueResolver($tokenStorage);
92+
$metadata = new ArgumentMetadata('foo', null, false, false, null, false, new CurrentUser());
93+
94+
$this->assertFalse($resolver->supports(Request::create('/'), $metadata));
95+
}
96+
8697
public function testIntegration()
8798
{
8899
$user = $this->createMock(UserInterface::class);

src/Symfony/Component/Translation/Dumper/XliffFileDumper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ private function dumpXliff2(string $defaultLocale, MessageCatalogue $messages, ?
150150
foreach ($messages->all($domain) as $source => $target) {
151151
$translation = $dom->createElement('unit');
152152
$translation->setAttribute('id', strtr(substr(base64_encode(hash('sha256', $source, true)), 0, 7), '/+', '._'));
153-
$name = $source;
154-
if (\strlen($source) > 80) {
155-
$name = substr(md5($source), -7);
153+
154+
if (\strlen($source) <= 80) {
155+
$translation->setAttribute('name', $source);
156156
}
157-
$translation->setAttribute('name', $name);
157+
158158
$metadata = $messages->getMetadata($source, $domain);
159159

160160
// Add notes section

src/Symfony/Component/Translation/Tests/Dumper/XliffFileDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function testFormatCatalogueXliff2()
4343
'foo' => 'bar',
4444
'key' => '',
4545
'key.with.cdata' => '<source> & <target>',
46+
'translation.key.that.is.longer.than.eighty.characters.should.not.have.name.attribute' => 'value',
4647
]);
4748
$catalogue->setMetadata('key', ['target-attributes' => ['order' => 1]]);
4849

src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@
1919
<target><![CDATA[<source> & <target>]]></target>
2020
</segment>
2121
</unit>
22+
<unit id="aF1tx51">
23+
<segment>
24+
<source>translation.key.that.is.longer.than.eighty.characters.should.not.have.name.attribute</source>
25+
<target>value</target>
26+
</segment>
27+
</unit>
2228
</file>
2329
</xliff>

0 commit comments

Comments
 (0)
0