Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serializer] Catch \Throwable in getCacheKey() #36336

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,12 @@ private function getCacheKey($format, array $context)
'ignored' => $this->ignoredAttributes,
'camelized' => $this->camelizedAttributes,
]));
} catch (\Exception $exception) {
} catch (\Throwable $exception) {
// The context cannot be serialized, skip the cache
return false;
} catch (\Exception $exception) {
// compatibility layer for PHP 5
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,7 @@ public function testNormalizeNotSerializableContext()
'bar' => null,
];

$this->assertEquals($expected, $this->normalizer->normalize($objectDummy, null, ['not_serializable' => function () {
}]));
$this->assertEquals($expected, $this->normalizer->normalize($objectDummy, null, ['not_serializable' => new NotSerializable()]));
}

public function testMaxDepth()
Expand Down Expand Up @@ -1102,3 +1101,15 @@ public function getFoo()
return $this->Foo;
}
}

class NotSerializable
{
public function __sleep()
{
if (class_exists(\Error::class)) {
throw new \Error('not serializable');
}

throw new \Exception('not serializable');
}
}