fix: SnapshotStore verweigert nicht kodierbare Snapshots
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
5ba52b98b3
commit
6ee8f9258a
@@ -38,11 +38,16 @@ class SnapshotStore
|
||||
/**
|
||||
* @param array<array-key, mixed> $data The area's raw inventory.
|
||||
* @throws SnapshotTooLarge
|
||||
* @throws RuntimeException When the option could not be written.
|
||||
* @throws RuntimeException When the snapshot cannot be encoded or the option could not be written.
|
||||
*/
|
||||
public function save(string $area, array $data, string $ability): string
|
||||
{
|
||||
$size = strlen((string) wp_json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
$json = wp_json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (! is_string($json)) {
|
||||
throw new RuntimeException(sprintf('snapshot %s could not be encoded', $area));
|
||||
}
|
||||
|
||||
$size = strlen($json);
|
||||
if ($size > self::MAX_BYTES) {
|
||||
throw new SnapshotTooLarge($size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user