[core] load null-strings as null, fixes #1023
This commit is contained in:
parent
29ff1b7333
commit
3d905b1055
2 changed files with 29 additions and 6 deletions
|
@ -90,13 +90,18 @@ class Image implements \ArrayAccess
|
|||
$t = (new \ReflectionProperty($this, $name))->getType();
|
||||
assert(!is_null($t));
|
||||
if(is_a($t, \ReflectionNamedType::class)) {
|
||||
if(is_null($value)) {
|
||||
$this->$name = null;
|
||||
} else {
|
||||
$this->$name = match($t->getName()) {
|
||||
"int" => is_null($value) ? $value : int_escape((string)$value),
|
||||
"bool" => is_null($value) ? $value : bool_escape((string)$value),
|
||||
"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)) {
|
||||
$value = null;
|
||||
|
|
18
core/tests/ImageTest.php
Normal file
18
core/tests/ImageTest.php
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
Reference in a new issue