[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,12 +90,17 @@ class Image implements \ArrayAccess
|
||||||
$t = (new \ReflectionProperty($this, $name))->getType();
|
$t = (new \ReflectionProperty($this, $name))->getType();
|
||||||
assert(!is_null($t));
|
assert(!is_null($t));
|
||||||
if(is_a($t, \ReflectionNamedType::class)) {
|
if(is_a($t, \ReflectionNamedType::class)) {
|
||||||
$this->$name = match($t->getName()) {
|
if(is_null($value)) {
|
||||||
"int" => is_null($value) ? $value : int_escape((string)$value),
|
$this->$name = null;
|
||||||
"bool" => is_null($value) ? $value : bool_escape((string)$value),
|
} else {
|
||||||
"string" => (string)$value,
|
$this->$name = match($t->getName()) {
|
||||||
default => $value,
|
"int" => int_escape((string)$value),
|
||||||
};
|
"bool" => bool_escape((string)$value),
|
||||||
|
"string" => (string)$value,
|
||||||
|
default => $value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} elseif(array_key_exists($name, static::$prop_types)) {
|
} elseif(array_key_exists($name, static::$prop_types)) {
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
|
|
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