From 3d905b1055afb3c84e55c149b4f755d9a3f561f9 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 12 Feb 2024 16:03:37 +0000 Subject: [PATCH] [core] load null-strings as null, fixes #1023 --- core/imageboard/image.php | 17 +++++++++++------ core/tests/ImageTest.php | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 core/tests/ImageTest.php 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); + } +}