Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Symfony/Component/Lock/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Jérémy Derussé <jeremy@derusse.com>
*/
final class Key
final class Key implements \Stringable
{
private ?float $expiringTime = null;
private array $state = [];
Expand Down Expand Up @@ -91,9 +91,9 @@ public function isExpired(): bool

public function __unserialize(array $data): void
{
$this->resource = $data['resource'];
$this->expiringTime = $data['expiringTime'];
$this->state = $data['state'];
$this->resource = $data['resource'] ?? $data["\0".self::class."\0resource"];
$this->expiringTime = $data['expiringTime'] ?? $data["\0".self::class."\0expiringTime"] ?? null;
$this->state = $data['state'] ?? $data["\0".self::class."\0state"] ?? [];
}

public function __serialize(): array
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Lock/Tests/KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public function testSerialize()
$this->assertEqualsWithDelta($key->getRemainingLifetime(), $copy->getRemainingLifetime(), 0.001);
}

public function testLegacyPayloadCanBeUnserialized()
{
$serialized = base64_decode('TzoyNjoiU3ltZm9ueVxDb21wb25lbnRcTG9ja1xLZXkiOjM6e3M6MzY6IgBTeW1mb255XENvbXBvbmVudFxMb2NrXEtleQByZXNvdXJjZSI7czo2OiJsZWdhY3kiO3M6NDA6IgBTeW1mb255XENvbXBvbmVudFxMb2NrXEtleQBleHBpcmluZ1RpbWUiO047czozMzoiAFN5bWZvbnlcQ29tcG9uZW50XExvY2tcS2V5AHN0YXRlIjthOjA6e319', true);

$key = unserialize($serialized, ['allowed_classes' => [Key::class]]);

$this->assertInstanceOf(Key::class, $key);
$this->assertSame('legacy', (string) $key);
$this->assertNull($key->getRemainingLifetime());
}

public function testUnserialize()
{
$key = new Key(__METHOD__);
Expand Down
Loading