Fixed Image height is not being saved

Kirby

Well-known member
Affected version
2.2
Steps to reproduce
  1. Insert an external image using the insert image toolbar icon
  2. Klick the image
  3. Click the resize icon
  4. Enter a new width and height
  5. Click Update
Expected Result
When making a preview or switching to BB-Code mode the new width and height are being used

Actual Result
Only the width seems to be processed
 
This bug might to be caused by \XF\Html\Renderer\BbCode::getAttachWidthAttribute():

PHP:
protected function getAttachWidthAttribute(Tag $tag)
{
    if ($style = $tag->attribute('style'))
    {
        if (isset($style['width']))
        {
            if (preg_match('/^(?P<width>[\d\.]+(?:px|%))$/i', $style['width'], $match))
            {
                return " width=\"{$match['width']}\"";
            }
        }
        if (isset($style['height']))
        {
            if (preg_match('/^(?P<height>[\d\.]+(?:px|%))$/i', $style['height'], $match))
            {
                return " height=\"{$match['height']}\"";
            }
        }
    }

    return '';
}

So if a valid width is set, it will never process the height.

Changing this to
PHP:
protected function getAttachWidthAttribute(Tag $tag)
{
    $attributes = '';
   
    if ($style = $tag->attribute('style'))
    {
        if (isset($style['width']))
        {
            if (preg_match('/^(?P<width>[\d\.]+(?:px|%))$/i', $style['width'], $match))
            {
                $attributes .= " width=\"{$match['width']}\"";
            }
        }
        if (isset($style['height']))
        {
            if (preg_match('/^(?P<height>[\d\.]+(?:px|%))$/i', $style['height'], $match))
            {
                $attributes .= " height=\"{$match['height']}\"";
            }
        }
    }

    return $attributes;
}
seems to fix it.

Btw: The method name is kinda misleading.
 
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.0 Beta 5).

Change log:
Return both width and height attributes if specified (and rename the method accordingly)
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom