Skip to content

Commit

Permalink
Ensure values have the right type when loading drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldiesmann committed Feb 9, 2025
1 parent 594b671 commit 5520b18
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Sources/Draft.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,40 @@ public function __construct(int $id_draft = 0, bool $check = true, array $recipi
foreach ($draft_info as $key => $value) {
switch ($key) {
case 'id_draft':
$this->id = $value;
$this->id = (int) $value;
break;

case 'id_topic':
case 'id_board':
case 'id_member':
$this->{substr($key, 3)} = (int) $value;
break;

case 'is_sticky':
$this->{substr($key, 3)} = $value;
$this->sticky = !empty($value);
break;

case 'id_reply':
$this->reply_to = $value;
$this->reply_to = (int) $value;
break;

case 'to_list':
$recipientsList = Utils::jsonDecode($draft_info['to_list'], true);
$this->recipients['to'] = $recipientsList['to'] ?? [];
$this->recipients['bcc'] = $recipientsList['bcc'] ?? [];
break;

// These have to be ints
case 'type':
case 'poster_time':
$this->type = (int) $value;
break;

// Boolean values
case 'smileys_enabled':
case 'locked':
$this->$key = !empty($value);
break;

default:
$this->$key = $value;
Expand Down

0 comments on commit 5520b18

Please sign in to comment.