2017-05-15, 03:24 PM
If the message is longer than the limit of the message field in the database, with MySQL strict mode enabled it throws an error instead of cutting the message after the limit.
To avoid this error in our forum, I added in function verify_message() in inc/datahandlers/post.php below
a check:
SQL Error:
1406 - Data too long for column 'message' at row 1
To avoid this error in our forum, I added in function verify_message() in inc/datahandlers/post.php below
// If this board has a maximum message length check if we're over it. Use strlen because SQL limits are in bytes
else if(strlen($post['message']) > $mybb->settings['maxmessagelength'] && $mybb->settings['maxmessagelength'] > 0 && !is_moderator($post['fid'], "", $post['uid']))
{
$this->set_error("message_too_long", array($mybb->settings['maxmessagelength'], strlen($post['message'])));
return false;
}
a check:
// If the message length is over SQL limits
else if(strlen($post['message']) > 65535)
{
global $db;
$fieldlength = $db->show_fields_from("posts");
if(is_array($fieldlength))
{
foreach ($fieldlength as $key => $fields)
{
if($fields['Field'] == 'message')
{
switch($fields['Type'])
{
case 'text':
{
$maximum = 65535;
}
break;
case 'mediumtext':
{
$maximum = 16777215;
}
break;
case 'longtext':
{
$maximum = 4294967295;
}
break;
default:
$maximum = 65535;
}
}
}
}
if(isset($maximum) && strlen($post['message']) > $maximum)
{
$this->set_error("message_too_long", array($maximum, strlen($post['message'])));
return false;
}
}