-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: null byte serialization issues (#64)
- Loading branch information
Showing
3 changed files
with
38 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Thomasjohnkane\Snooze; | ||
|
||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Database\ConnectionInterface; | ||
use Illuminate\Database\PostgresConnection; | ||
use Illuminate\Queue\SerializesAndRestoresModelIdentifiers; | ||
use Illuminate\Support\Str; | ||
|
||
class Serializer | ||
{ | ||
use SerializesAndRestoresModelIdentifiers; | ||
|
||
public static function create(): self | ||
{ | ||
return new self(); | ||
} | ||
/** @var ConnectionInterface */ | ||
protected $connection; | ||
|
||
public function serializeNotifiable(object $notifiable): string | ||
public function __construct(ConnectionInterface $connection) | ||
{ | ||
return serialize(self::getSerializedPropertyValue(clone $notifiable)); | ||
$this->connection = $connection; | ||
} | ||
|
||
public function serializeNotification(Notification $notification): string | ||
public function serialize(object $notifiable): string | ||
{ | ||
return serialize(clone $notification); | ||
} | ||
$result = serialize($this->getSerializedPropertyValue(clone $notifiable)); | ||
|
||
public function unserializeNotifiable(string $serialized) | ||
{ | ||
return $this->getRestoredPropertyValue(unserialize($serialized)); | ||
if ($this->connection instanceof PostgresConnection && Str::contains($result, "\0")) { | ||
$result = base64_encode($result); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function unserializeNotification(string $serialized) | ||
public function unserialize(string $serialized) | ||
{ | ||
return unserialize($serialized); | ||
if ($this->connection instanceof PostgresConnection && ! Str::contains($serialized, [':', ';'])) { | ||
$serialized = base64_decode($serialized); | ||
} | ||
|
||
$object = unserialize($serialized); | ||
|
||
return $this->getRestoredPropertyValue( | ||
$object | ||
); | ||
} | ||
} |