diff --git a/core/imageboard/image.php b/core/imageboard/image.php index 196c2079..2aafc217 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -90,12 +90,17 @@ class Image implements \ArrayAccess $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)) { diff --git a/core/tests/ImageTest.php b/core/tests/ImageTest.php new file mode 100644 index 00000000..8c860a9a --- /dev/null +++ b/core/tests/ImageTest.php @@ -0,0 +1,18 @@ +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); + } +}