Magento – Wrong URL returned by WYSIWYG editor for images

ce-1.7.0.2imagemagento-1.7wysiwyg

I've noticed a weird behavior from the WYSIWYG editor in the product description. Whenever I insert an image it will output

<img src="{{media url="http://example.com/media/wysiwyg/the-picture.jpg"}}" alt="" />

while in another context, such as static blocks editing, it would output

<img src="{{media url=wysiwyg/the-picture.jpg"}}" alt="" />

This results in displaying

<img alt="" src="http://example.com/media/http://example.com/media/wysiwyg/the-picture.jpg">

which is obviously not what I want.

I've searched on different topics, and no one seems to have that specific problem. Did anyone come across this, does anyone have a fix?

Best Answer

the error is due to Mage::getBaseUrl('media') does not pass the store parameter !

To solve this bug, change in :

app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php

Find function : getImageHtmlDeclaration

and change :

$mediaPath = str_replace(Mage::getBaseUrl('media'), '', $fileurl);

by

$mediaPath = str_replace(mage::app()->getStore($this->_storeId)->getBaseUrl('media'), '', $fileurl);
Related Topic