Fixed Error with too long username when creating a thread by a guest

Affected version
2.1, 2.2 (2.0?)

NikitOS

Active member
Hello

An error occurs when a guest creates a thread and enters a username that is more than 50 characters long:
Attempted to convert NULL to string/binary [last_post_username]
#0 src/XF/Mvc/Entity/Entity.php(637): XF\Mvc\Entity\Entity->_castValueToType(NULL, 'last_post_usern...', 5, Array)
#1 src/XF/Mvc/Entity/Entity.php(567): XF\Mvc\Entity\Entity->set('last_post_usern...', NULL)
#2 src/XF/Service/Thread/Creator.php(413): XF\Mvc\Entity\Entity->__set('last_post_usern...', NULL)
#3 src/XF/Service/Thread/Creator.php(421): XF\Service\Thread\Creator->finalSetup()
#4 src/XF/Service/ValidateAndSavableTrait.php(17): XF\Service\Thread\Creator->_validate()
#5 src/XF/Pub/Controller/Forum.php(888): XF\Service\Thread\Creator->validate(NULL)
#6 src/XF/Mvc/Dispatcher.php(350): XF\Pub\Controller\Forum->actionPostThread(Object(XF\Mvc\ParameterBag))
#7 src/XF/Mvc/Dispatcher.php(257): XF\Mvc\Dispatcher->dispatchClass('XF:Forum', 'PostThread', Object(XF\Mvc\RouteMatch), Object(XF\Pub\Controller\Forum), NULL)
#8 src/XF/Mvc/Dispatcher.php(113): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Pub\Controller\Forum), NULL)
#9 src/XF/Mvc/Dispatcher.php(55): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#10 src/XF/App.php(2337): XF\Mvc\Dispatcher->run()
#11 src/XF.php(488): XF\App->run()
#12 index.php(20): XF::runApp('XF\\Pub\\App')
#13 {main}
array(4) {
'url' =>
string(43) "/index.php?forums/multi-type.11/post-thread"
'referrer' =>
string(66) "http://xf22-2.localhost/index.php?forums/multi-type.11/post-thread"
'_GET' =>
array(1) {
'forums/multi-type_11/post-thread' =>
string(0) ""
}
'_POST' =>
array(10) {
'title' =>
string(2) "QQ"
'discussion_type' =>
string(10) "discussion"
'message_html' =>
string(9) "<p>QQ</p>"
'_xfUsername' =>
string(941) "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris commodo, elit ac aliquet rhoncus, magna mauris elementum velit, at lacinia purus diam nec sem. Nam tincidunt lacus eu mauris venenatis scelerisque. Sed posuere, justo non ullamcorper vestibulum, urna nibh tempor dolor, id venenatis mi lacus eleifend tellus. Donec ultricies sapien a tortor pretium, non dignissim libero pulvinar. Sed mollis sapien viverra dui cursus, nec aliquet est congue. In tempus semper lorem interdum laoreet. Nulla id magna "...
'_xfToken' =>
string(8) "********"
'_xfRequestUri' =>
string(43) "/index.php?forums/multi-type.11/post-thread"
'_xfWithData' =>
string(1) "1"
'_xfResponseType' =>
string(4) "json"
}
}

setAsSaved does not validate the length of the value, but when the visitor's username is set to the Thread entity, validation is performed, but no error is displayed and the value remains null.
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.6).

Change log:
Validate usernames before trying to set them when creating threads as a guest
There may be a delay before changes are rolled out to the XenForo Community.
 
Top