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
This commit is contained in:
Nicolas Grekas 2020-05-16 11:03:35 +02:00
commit fb4c3f920f
7 changed files with 68 additions and 7 deletions

View File

@ -54,10 +54,16 @@ class AuthenticationProviderManagerTest extends TestCase
public function testAuthenticateWhenProviderReturnsAccountStatusException()
{
$secondAuthenticationProvider = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface')->getMock();
$manager = new AuthenticationProviderManager([
$this->getAuthenticationProvider(true, null, 'Symfony\Component\Security\Core\Exception\AccountStatusException'),
$secondAuthenticationProvider,
]);
// AccountStatusException stops authentication
$secondAuthenticationProvider->expects($this->never())->method('supports');
try {
$manager->authenticate($token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
$this->fail();

View File

@ -522,12 +522,21 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)
{
try {
if (null !== $parameter->getClass()) {
if (\PHP_VERSION_ID < 70100 && null !== $parameterClass = $parameter->getClass()) {
$parameterClass = $parameterClass->name;
} elseif (\PHP_VERSION_ID >= 70100 && $parameter->hasType() && ($parameterType = $parameter->getType()) && !$parameterType->isBuiltin()) {
$parameterClass = $parameterType->getName();
new \ReflectionClass($parameterClass); // throws a \ReflectionException if the class doesn't exist
} else {
$parameterClass = null;
}
if (null !== $parameterClass) {
if (!$this->serializer instanceof DenormalizerInterface) {
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));
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));
}
$parameterClass = $parameter->getClass()->getName();
$parameterData = $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
return $this->serializer->denormalize($parameterData, $parameterClass, $format, $this->createChildContext($context, $parameterName, $format));
}
} catch (\ReflectionException $e) {
throw new RuntimeException(sprintf('Could not determine the class of the parameter "%s".', $parameterName), 0, $e);
@ -535,7 +544,8 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
if (!$parameter->getType()->allowsNull()) {
throw $e;
}
$parameterData = null;
return null;
}
return $parameterData;

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Translation\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\Exception\RuntimeException;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Translator;
@ -688,6 +689,16 @@ class TranslatorTest extends TestCase
// unchanged if it can't be found
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, ['%count%' => 10]));
}
public function testMissingLoaderForResourceError()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('No loader is registered for the "twig" format when loading the "messages.en.twig" resource.');
$translator = new Translator('en');
$translator->addResource('twig', 'messages.en.twig', 'en');
$translator->getCatalogue('en');
}
}
class StringClass

View File

@ -428,7 +428,11 @@ EOF
if (isset($this->resources[$locale])) {
foreach ($this->resources[$locale] as $resource) {
if (!isset($this->loaders[$resource[0]])) {
throw new RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0]));
if (\is_string($resource[1])) {
throw new RuntimeException(sprintf('No loader is registered for the "%s" format when loading the "%s" resource.', $resource[0], $resource[1]));
}
throw new RuntimeException(sprintf('No loader is registered for the "%s" format.', $resource[0]));
}
$this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]));
}

View File

@ -91,6 +91,8 @@ class SplCaster
];
$prefix = Caster::PREFIX_VIRTUAL;
unset($a["\0SplFileInfo\0fileName"]);
unset($a["\0SplFileInfo\0pathName"]);
if (false === $c->getPathname()) {
$a[$prefix.'⚠'] = 'The parent constructor was not called: the object is in an invalid state';

View File

@ -756,7 +756,8 @@ class Parser
$lines[] = trim($this->currentLine);
// quoted string values end with a line that is terminated with the quotation character
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
$escapedLine = str_replace(['\\\\', '\\"'], '', $this->currentLine);
if ('' !== $escapedLine && substr($escapedLine, -1) === $quotation) {
break;
}
}

View File

@ -1530,6 +1530,33 @@ YAML;
$this->assertSame($expected, $this->parser->parse($yaml));
}
public function testEscapedQuoteInQuotedMultiLineString()
{
$yaml = <<<YAML
foobar: "foo
\\"bar\\"
baz"
YAML;
$expected = [
'foobar' => 'foo "bar" baz',
];
$this->assertSame($expected, $this->parser->parse($yaml));
}
public function testBackslashInQuotedMultiLineString()
{
$yaml = <<<YAML
foobar: "foo
bar\\\\"
YAML;
$expected = [
'foobar' => 'foo bar\\',
];
$this->assertSame($expected, $this->parser->parse($yaml));
}
public function testParseMultiLineUnquotedString()
{
$yaml = <<<EOT