Fixed BB code HEADING

smozgur

Well-known member
Affected version
2.2.1
Apparently BB code HEADING is causing problems. Its integer parameter looks to be required.
So, you can't type [heading] in a message. It is causing a server error.
TypeError: Macro public: post_macros :: post_user_content() error: Argument 1 passed to XF\BbCode\Renderer\Html::getHeadingTagMap() must be of the type int, null given, called in /var/www/vhosts/domain/public/board/src/XF/BbCode/Renderer/Html.php on line 834 src/XF/BbCode/Renderer/Html.php:846
To reproduce the error: Enter [heading] (without PLAIN BB code as I did to be able to write it) and try to preview.
If it is an existing post, then it generates server error and return empty post.

Edit: I just locked myself in this thread by trying to reproduce the same behavior in the reply post. I entered heading tag without parameter, and previewed the post. Since my post is auto-saved, I don't even have a reply option now! So I am editing here. It is really bad.

Possible solution (as I will extend the controller temporarily to avoid its harm) in the following file:
src/XF/BbCode/Renderer/Html.php
PHP:
protected function getHeadingTagMap(int $type): string
{
   switch ($type)
   {
      case 1: return 'h2';
      case 2: return 'h3';
      case 3: return 'h4';
      default: return 'div';
   }
}

Remove int variable type from $type parameter.
PHP:
protected function getHeadingTagMap($type): string
{
// ...
}

Or make the call by checking the parameter and assign something as default if it is null to return div wrapper.
 
Last edited:
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.2).

Change log:
Handle heading BB codes without a type option
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom