diff --git a/lib/Misc/Context.php b/lib/Misc/Context.php index fa6241a9..87ada397 100644 --- a/lib/Misc/Context.php +++ b/lib/Misc/Context.php @@ -34,7 +34,7 @@ class Context { public $labelName; public $labelled = null; public $annotated = null; - public $searchTerms = []; + public $searchTerms = null; protected $props = []; @@ -67,8 +67,9 @@ class Context { protected function cleanStringArray(array $spec): array { $spec = array_values($spec); - for ($a = 0; $a < sizeof($spec); $a++) { - if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING))) { + $stop = sizeof($spec); + for ($a = 0; $a < $stop; $a++) { + if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING | ValueInfo::M_DROP) ?? "")) { $spec[$a] = $str; } else { unset($spec[$a]); diff --git a/tests/cases/Misc/TestContext.php b/tests/cases/Misc/TestContext.php index 07d6adb0..b767d115 100644 --- a/tests/cases/Misc/TestContext.php +++ b/tests/cases/Misc/TestContext.php @@ -7,6 +7,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\TestCase\Misc; use JKingWeb\Arsse\Misc\Context; +use JKingWeb\Arsse\Misc\ValueInfo; /** @covers \JKingWeb\Arsse\Misc\Context */ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { @@ -48,6 +49,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { 'labelName' => "Rush", 'labelled' => true, 'annotated' => true, + 'searchTerms' => ["foo", "bar"], ]; $times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince']; $c = new Context; @@ -70,7 +72,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { } } - public function testCleanArrayValues() { + public function testCleanIdArrayValues() { $methods = ["articles", "editions"]; $in = [1, "2", 3.5, 3.0, "ook", 0, -20, true, false, null, new \DateTime(), -1.0]; $out = [1,2, 3]; @@ -79,4 +81,15 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertSame($out, $c->$method($in)->$method, "Context method $method did not return the expected results"); } } + + public function testCleanStringArrayValues() { + $methods = ["searchTerms"]; + $now = new \DateTime; + $in = [1, 3.0, "ook", 0, true, false, null, $now, ""]; + $out = ["1", "3", "ook", "0", valueInfo::normalize($now, ValueInfo::T_STRING)]; + $c = new Context; + foreach ($methods as $method) { + $this->assertSame($out, $c->$method($in)->$method, "Context method $method did not return the expected results"); + } + } }