8000 Merge branch '3.4' into 4.4 · symfony/symfony@fb4c3f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit fb4c3f9

Browse files
Merge branch '3.4' into 4.4
* 3.4: [VarDumper] fix for change in PHP 7.4.6 Added regression test for AccountStatusException behavior (ref #36822) embed resource name in error message [Serializer] fix issue with PHP 8 [Yaml] Fix escaped quotes in quoted multi-line string
2 parents 9bcf9c1 + 924822c commit fb4c3f9

File tree

7 files changed

+68
-7
lines changed

7 files changed

+68
-7
lines changed

src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationProviderManagerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@ public function testAuthenticateWhenNoProviderSupportsToken()
5454

5555
public function testAuthenticateWhenProviderReturnsAccountStatusException()
5656
{
57+
$secondAuthenticationProvider = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface')->getMock();
58+
5759
$manager = new AuthenticationProviderManager([
5860
$this->getAuthenticationProvider(true, null, 'Symfony\Component\Security\Core\Exception\AccountStatusException'),
61+
$secondAuthenticationProvider,
5962
]);
6063

64+
// AccountStatusException stops authentication
65+
$secondAuthenticationProvider->expects($this->never())->method('supports');
66+
6167
try {
6268
$manager->authenticate($token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
6369
$this->fail();

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,20 +522,30 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
522522
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, $parameterNam 10000 e, $parameterData, array $context, $format = null)
523523
{
524524
try {
525-
if (null !== $parameter->getClass()) {
525+
if (\PHP_VERSION_ID < 70100 && null !== $parameterClass = $parameter->getClass()) {
526+
$parameterClass = $parameterClass->name;
527+
} elseif (\PHP_VERSION_ID >= 70100 && $parameter->hasType() && ($parameterType = $parameter->getType()) && !$parameterType->isBuiltin()) {
528+
$parameterClass = $parameterType->getName();
529+
new \ReflectionClass($parameterClass); // throws a \ReflectionException if the class doesn't exist
530+
} else {
531+
$parameterClass = null;
532+
}
533+
534+
if (null !== $parameterClass) {
526535
if (!$this->serializer instanceof DenormalizerInterface) {
527-
throw new LogicException(sprintf('Cannot create an instance of "%s" from serialized data because the serializer inject in "%s" is not a denormalizer.', $parameter->getClass(), self::class));
536+
throw new LogicException(sprintf('Cannot create an instance of "%s" from serialized data because the serializer inject in "%s" is not a denormalizer.', $parameterClass, static::class));
528537
}
529-
$parameterClass = $parameter->getClass()->getName();
530-
$parameterData = $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
538+
539+
return $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
531540
}
532541
} catch (\ReflectionException $e) {
533542
throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $parameterName), 0, $e);
534543
} catch (MissingConstructorArgumentsException $e) {
535544
if (!$parameter->getType()->allowsNull()) {
536545
throw $e;
537546
}
538-
$parameterData = null;
547+
548+
return null;
539549
}
540550

541551
return $parameterData;

src/Symfony/Component/Translation/Tests/TranslatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Translation\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Translation\Exception\RuntimeException;
1516
use Symfony\Component\Translation\Loader\ArrayLoader;
1617
use Symfony\Component\Translation\MessageCatalogue;
1718
use Symfony\Component\Translation\Translator;
@@ -688,6 +689,16 @@ public function testTransChoiceFallbackWithNoTranslation()
688689
// unchanged if it can't be found
689690
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
690691
}
692+
693+
public function testMissingLoaderForResourceError()
694+
{
695+
$this->expectException(RuntimeException::class);
696+
$this->expectExceptionMessage('No loader is registered for the "twig" format when loading the "messages.en.twig" resource.');
697+
698+
$translator = new Translator('en');
699+
$translator->addResource('twig', 'messages.en.twig', 'en');
700+
$translator->getCatalogue('en');
701+
}
691702
}
692703

693704
class StringClass

src/Symfony/Component/Translation/Translator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,11 @@ protected function doLoadCatalogue(string $locale): void
428428
if (isset($this->resources[$locale])) {
429429
foreach ($this->resources[$locale] as $resource) {
430430
if (!isset($this->loaders[$resource[0]])) {
431-
throw new RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0]));
431+
if (\is_string($resource[1])) {
432+
throw new RuntimeException(sprintf('No loader is registered for the "%s" format when loading the "%s" resource.', $resource[0], $resource[1]));
433+
}
434+
435+
throw new RuntimeException(sprintf('No loader is registered for the "%s" format.', $resource[0]));
432436
}
433437
$this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]));
434438
}

src/Symfony/Component/VarDumper/Caster/SplCaster.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public static function castFileInfo(\SplFileInfo $c, array $a, Stub $stub, $isNe
9191
];
9292

9393
$prefix = Caster::PREFIX_VIRTUAL;
94+
unset($a["\0SplFileInfo\0fileName"]);
95+
unset($a["\0SplFileInfo\0pathName"]);
9496

9597
if (false === $c->getPathname()) {
9698
$a[$prefix.''] = 'The parent constructor was not called: the object is in an invalid state';

src/Symfony/Component/Yaml/Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,8 @@ private function parseValue(string $value, int $flags, string $context)
756756
$lines[] = trim($this->currentLine);
757757

758758
// quoted string values end with a line that is terminated with the quotation character
759-
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
759+
$escapedLine = str_replace(['\\\\', '\\"'], '', $this->currentLine);
760+
if ('' !== $escapedLine && substr($escapedLine, -1) === $quotation) {
760761
break;
761762
}
762763
}
10000

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,33 @@ public function testBlankLinesInQuotedMultiLineString()
15301530
$this->assertSame($expected, $this->parser->parse($yaml));
15311531
}
15321532

1533+
public function testEscapedQuoteInQuotedMultiLineString()
1534+
{
1535+
$yaml = <<<YAML
1536+
foobar: "foo
1537+
\\"bar\\"
1538+
baz"
1539+
YAML;
1540+
$expected = [
1541+
'foobar' => 'foo "bar" baz',
1542+
];
1543+
1544+
$this->assertSame($expected, $this->parser->parse($yaml));
1545+
}
1546+
1547+
public function testBackslashInQuotedMultiLineString()
1548+
{
1549+
$yaml = <<<YAML
1550+
foobar: "foo
1551+
bar\\\\"
1552+
YAML;
1553+
$expected = [
1554+
'foobar' => 'foo bar\\',
1555+
];
1556+
1557+
$this->assertSame($expected, $this->parser->parse($yaml));
1558+
}
1559+
15331560
public function testParseMultiLineUnquotedString()
15341561
{
15351562
$yaml = <<<EOT

0 commit comments

Comments
 (0)
0