﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
8602	Unnecessary calls to images without baseHref	pm_ele	Frederico Caldeira Knabben	"When displaying images using relative urls and config.baseHref, everytime I switch to wysiwyg mode there is a call made to the image using only the relative url and totally ignoring the baseHref. Obviously this fails into a 404 (or some other error code depending on the environnement).
The image is still displayed, but there is also this unnecessary 404 call.
Please note also that if you're testing this on local static files (i mean something like C:/some_directories/mypage.html) the call won't show up on Firebug, you will need to run it on a server like wamp.

You can reproduce it easily on the online demo with Firebug :
- go to http://ckeditor.com/demo
- go to source mode
- remove all source and paste only the following :
{{{
 <img src=""logo3w.png""/>
}}}

- type in Firebug console : 
{{{
CKEDITOR.instances.editor1.config.baseHref = 'http://www.google.fr/images/srpr/';
}}}

- clear all firebug console and network panel
- hit the wysiwyg mode

you should see the Google logo, and a 404 showing up in both console et network panels.

I've located the where the call is made, it's in plugins/htmldataprocessor/plugin.js, in the toHtml function :

    
{{{
    // Call the browser to help us fixing a possibly invalid HTML
    // structure.
    var div = new CKEDITOR.dom.element( 'div' );
    // Add fake character to workaround IE comments bug. (#3801)
    div.setHtml( 'a' + data );
    data = div.getHtml().substr( 1 );
}}}


The data is submitted to the browser, causing it to interpret the <img> tags without taking the config.baseHref into account.

I've found a solution by using a regexp on the data : I turn all the src attributes into data attributes and back just before and after submitting the data to the browser. I'm not sure it's best way but I'm using it on the ckeditor on my website and it works fine. I can't make a patch file but here's how I've altered the code :

    
{{{
    //Call the browser to help us fixing a possibly invalid HTML
    // structure.        
    var fakeSrcAttribute = 'data-cke-faked-src';
    data = data.replace(/(<img[^>]+)src(\s*=)/ig, '$1' + fakeSrcAttribute + '$2');        
    var div = new CKEDITOR.dom.element( 'div' );
    // Add fake character to workaround IE comments bug. (#3801)
    div.setHtml( 'a' + data );
    data = div.getHtml().substr( 1 );
    data = data.replace(new RegExp('(<img[^>]+)' + fakeSrcAttribute + '(\\s*=)', 'ig'), '$1src$2');

}}}"	Bug	closed	Normal	CKEditor 3.6.3	General		fixed	HasPatch IE	
