Merge branch '5.2' into 5.x

* 5.2:
  [Uid] Fix time to float conversion
  [Serializer] Prevent access to private properties without getters
This commit is contained in:
Nicolas Grekas 2021-01-27 19:13:13 +01:00
commit e2e2640d5a
5 changed files with 49 additions and 5 deletions

View File

@ -111,8 +111,9 @@ class ObjectNormalizer extends AbstractObjectNormalizer
// properties
foreach ($reflClass->getProperties() as $reflProperty) {
$isPublic = $reflProperty->isPublic();
if ($checkPropertyInitialization) {
$isPublic = $reflProperty->isPublic();
if (!$isPublic) {
$reflProperty->setAccessible(true);
}
@ -120,9 +121,10 @@ class ObjectNormalizer extends AbstractObjectNormalizer
unset($attributes[$reflProperty->name]);
continue;
}
if (!$isPublic) {
continue;
}
}
if (!$isPublic) {
continue;
}
if ($reflProperty->isStatic() || !$this->isAllowedAttribute($object, $reflProperty->name, $format, $context)) {

View File

@ -0,0 +1,23 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Serializer\Tests\Fixtures;
final class DummyPrivatePropertyWithoutGetter
{
private $foo = 'foo';
private $bar = 'bar';
public function getBar()
{
return $this->bar;
}
}

View File

@ -33,6 +33,7 @@ use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\Tests\Fixtures\Annotations\GroupDummy;
use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy;
use Symfony\Component\Serializer\Tests\Fixtures\DummyPrivatePropertyWithoutGetter;
use Symfony\Component\Serializer\Tests\Fixtures\OtherSerializedNameDummy;
use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy;
use Symfony\Component\Serializer\Tests\Fixtures\Php74DummyPrivate;
@ -140,6 +141,15 @@ class ObjectNormalizerTest extends TestCase
);
}
public function testNormalizeObjectWithPrivatePropertyWithoutGetter()
{
$obj = new DummyPrivatePropertyWithoutGetter();
$this->assertEquals(
['bar' => 'bar'],
$this->normalizer->normalize($obj, 'any')
);
}
public function testDenormalize()
{
$obj = $this->normalizer->denormalize(

View File

@ -124,7 +124,7 @@ class BinaryUtil
$time = self::add($time, self::TIME_OFFSET_COM2);
if ($time >= self::TIME_OFFSET_COM2) {
$time = -1 * self::toBase($time ^ "\xff\xff\xff\xff\xff\xff\xff\xff", self::BASE10);
$time = -1 * (self::toBase($time ^ "\xff\xff\xff\xff\xff\xff\xff\xff", self::BASE10) + 1);
} else {
$time[0] = $time[0] & "\x7F";
$time = self::toBase($time, self::BASE10);

View File

@ -307,4 +307,13 @@ class UuidTest extends TestCase
{
$this->assertInstanceOf(CustomUuid::class, CustomUuid::fromString(self::A_UUID_V4));
}
public function testGetTime()
{
$this->assertSame(103072857660.6847, ((new UuidV1('ffffffff-ffff-1fff-a456-426655440000'))->getTime()));
$this->assertSame(0.0000001, ((new UuidV1('13814001-1dd2-11b2-a456-426655440000'))->getTime()));
$this->assertSame(0.0, (new UuidV1('13814000-1dd2-11b2-a456-426655440000'))->getTime());
$this->assertSame(-0.0000001, (new UuidV1('13813fff-1dd2-11b2-a456-426655440000'))->getTime());
$this->assertSame(-12219292800.0, ((new UuidV1('00000000-0000-1000-a456-426655440000'))->getTime()));
}
}