Skip to content

Commit

Permalink
[core] load null-strings as null, fixes #1023
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Feb 12, 2024
1 parent 2acc3dd commit ddf1cde
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/imageboard/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,17 @@ public function __construct(?array $row = null)
$t = (new \ReflectionProperty($this, $name))->getType();
assert(!is_null($t));
if(is_a($t, \ReflectionNamedType::class)) {
$this->$name = match($t->getName()) {
"int" => is_null($value) ? $value : int_escape((string)$value),
"bool" => is_null($value) ? $value : bool_escape((string)$value),
"string" => (string)$value,
default => $value,
};
if(is_null($value)) {
$this->$name = null;
} else {
$this->$name = match($t->getName()) {
"int" => int_escape((string)$value),
"bool" => bool_escape((string)$value),
"string" => (string)$value,
default => $value,
};
}

}
} elseif(array_key_exists($name, static::$prop_types)) {
if (is_null($value)) {
Expand Down
18 changes: 18 additions & 0 deletions core/tests/ImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Shimmie2;

require_once "core/imageboard/image.php";

class ImageTest extends ShimmiePHPUnitTestCase
{
public function testLoadData(): void
{
$this->log_in_as_user();
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "question? colon:thing exclamation!");
$image = Image::by_id($image_id_1);
$this->assertNull($image->source);
}
}

0 comments on commit ddf1cde

Please sign in to comment.