- Affected version
- 2.3.2
XF\Criteria\UserCriteria::_matchEmailSearch
fails for guest users
Code:
TypeError: XF\Util\Str::strtolower(): Argument #1 ($string) must be of type string, null given, called in /var/www/html/src/XF/Criteria/AbstractCriteria.php on line 206 src\XF\Util\Str.php:210
Generated by: Unknown account Aug 17, 2024 at 9:11 PM
Code:
Stack trace
#0 src\XF\Criteria\AbstractCriteria.php(206): XF\Util\Str::strtolower(NULL)
#1 src\XF\Criteria\UserCriteria.php(101): XF\Criteria\AbstractCriteria->findNeedle('rr.com,roadrunn...', NULL)
#2 src\XF\Criteria\AbstractCriteria.php(67): XF\Criteria\UserCriteria->_matchEmailSearch(Array, Object(XF\Entity\User))
#3 src\XF\NoticeList.php(99): XF\Criteria\AbstractCriteria->isMatched(Object(XF\Entity\User))
#4 src\XF\Pub\App.php(658): XF\NoticeList->addConditionalNotice(80, 'scrolling', '<p>@RoadRunner ...', Array)
#5 src\XF\Pub\App.php(593): XF\Pub\App->getNoticeList(Array)
#6 src\XF\App.php(2560): XF\Pub\App->renderPageHtml('<div class="blo...', Array, Object(XF\Mvc\Reply\Message), Object(XF\Mvc\Renderer\Html))
#7 src\XF\Mvc\Dispatcher.php(414): XF\App->renderPage('<div class="blo...', Object(XF\Mvc\Reply\Message), Object(XF\Mvc\Renderer\Html))
#8 src\XF\Mvc\Dispatcher.php(66): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\Message), 'html')
#9 src\XF\App.php(2813): XF\Mvc\Dispatcher->run()
#10 src\XF.php(802): XF\App->run()
#11 index.php(23): XF::runApp('XF\\Pub\\App')
#12 {main}
This comes from
$user->email
being null
:
PHP:
protected function _matchEmailSearch(array $data, User $user)
{
if ($this->findNeedle($data['needles'], $user->email) === false)
{
return false;
}
else
{
return true;
}
}
But the actual root causes is, the type hint is saying
string
not string | null
and thus for guest users is created with a value of null
PHP:
public static function getStructure(Structure $structure)
{
$structure->table = 'xf_user';
...
'email' => ['type' => self::STR, 'maxLength' => 120],
default = ''
stanza, so it defaults to null
. This is actually a flaw in the property type hinting from xf-dev:entity-class-properties
. It only inspects nullable
and type
flags, and should add the | null
to the type definition if there is no default value.Alternatively, new entities should have a default value for columns initialized if they aren't set tot nullable. (ie empty string, 0 or whatever)