Ticket #5218 (closed Bug: fixed)

Opened 5 years ago

Last modified 4 years ago

FF: Copy/paste of an image from same domain as CKeditor changes URL to relative URL

Reported by: omkar Owned by: Saare
Priority: Normal Milestone: CKEditor 3.4.1
Component: Core : Pasting Version: 3.1
Keywords: HasPatch Cc: VincentK, sim@…

Description

This issue occurs only in Firefox.

To reproduce:

  1. Go to an instance of CKEditor (eg http://drupal.ckeditor.com/)
  2. Add an image that uses the same domain (eg http://drupal.ckeditor.com/images/logo-ie.png)
  3. Check image properties in CKEditor to verify the full URL is listed
  4. Copy and paste the image
  5. Check image properties on the pasted image - URL has been modified

See attached screenshot.

My limited testing of a couple OSes and a few browsers shows that this issue occurs only in Firefox:

OS: OSX 10.6.2

Issue occurs in Firefox 3.5.8 (see screenshot) Issue does not occur in Chrome 5.0.307.9 beta Issue does not occur in Safari 4.0.4 (6531.21.10)

OS: Windows XP

Issue occurs in Firefox 3.5.8 Issue does not occur in IE 8.0.6001.18702

Attachments

ckEditorFFBug.png (88.1 KB) - added by omkar 5 years ago.
Screenshot of the URL being modified in Firefox 3.5.8
5218.patch (1.4 KB) - added by jonathonsim 5 years ago.
Fixed version of the patch
5218.2.patch (1.4 KB) - added by Saare 4 years ago.
5218_3.patch (1.4 KB) - added by Saare 4 years ago.

Change History

Changed 5 years ago by omkar

Screenshot of the URL being modified in Firefox 3.5.8

comment:1 Changed 5 years ago by laurentl

  • Component changed from General to Core : Pasting

OS: Linux

Issue occurs in Firefox 3.6 OK on Chromium 5.0.342.9 (43360)

OS: Windows XP

Issue occurs in Firefox 3.6 Issue occurs in IE 7

comment:2 Changed 5 years ago by alfonsoml

  • Cc VincentK added

#5665 has been marked as dup

comment:3 Changed 5 years ago by jonathonsim

This bug also occurs on the latest nightly releases (to easily test it switch to source mode and enter "<img src="/test/test.png">" then switch back and cut-and-paste the resulting image - when you switch to source mode you will see it is now a relative url)

The issue is that firefox rewrites the image src attribute when you paste them, making them relative to the path to the editor (which may not be correct when you view the HTML elsewhere).

We have had success with the attached patch to htmldataprocessor which rewrites the src back to the _cke_saved_src

Changed 5 years ago by jonathonsim

Fixed version of the patch

comment:4 Changed 5 years ago by jonathonsim

  • Cc sim@… added

The original patch unfortunately didn't fix it (I'm not sure why in my original testing I though it did), but I've uploaded a fixed version that does.

comment:5 Changed 5 years ago by fredck

  • Keywords Confirmed added
  • Milestone set to CKEditor 3.5

The fact is that, theoretically, the original _cke_saved_src attribute should be also pasted, and then used by the editor in the image dialog and when outputting data. I think the default data processing on pasting is instead overwritting the already available _cke_saved_src attribute, replacing it with the wrong src. This is the thing to be fixed.

comment:6 Changed 5 years ago by jonathonsim

That is exactly what's happening (I had to trace this through to fix it in our setup). I thought it was probably a bit ambitious for me to try to "fix" it without really knowing how it works, the attached patch is at least less invasive

FYI what I found was :

  • the cke_saved_src is pasted correctly (my patch works by copying it back into the img src attribute on paste), but firefox has munged the src attribute
  • When you paste the "paste" event handler in clipboard/plugin.js calls
editor.insertHtml( data[ 'html' ] );

which triggers an event "inserthtml" which runs CKEDITOR.htmlDataProcessor.toHtml in htmldataprocessor/plugin.js, which runs this:

	function protectAttributes( html )
	{
		return html.replace( protectAttributeRegex, '$& _cke_saved_$1' );
	}

which overrides the cke_saved_src with the modified one firefox just pasted.

I assume though that its probably not appropriate though to just skip protectAttributes for pasted HTML (it wasn't necessarily pasted from within a ckeditor instance) - perhaps if it were modified not to overwrite existing cke_saved_src attributes in pasted code?

comment:7 Changed 5 years ago by fredck

You found the root of the problem. My suggestion is changing the data processor so it'll create the cke_saved_src attribute only if it doesn't exist.

comment:8 Changed 4 years ago by comp615

Another post which I believe might be related to this problem? Could serve as a good test case as well.

http://cksource.com/forums/viewtopic.php?f=11&t=19445

comment:9 Changed 4 years ago by tobiasz.cudnik

  • Status changed from confirmed to assigned
  • Owner set to tobiasz.cudnik
  • Keywords HasPatch added

Changed 4 years ago by Saare

comment:10 Changed 4 years ago by Saare

  • Owner changed from tobiasz.cudnik to Saare
  • Status changed from assigned to review

comment:11 Changed 4 years ago by tobiasz.cudnik

  • Status changed from review to review_passed

comment:12 Changed 4 years ago by fredck

  • Status changed from review_passed to review_failed

There is no need to have the entire _cke_saved_src attribute check, including its value, in the findSavedSrcRegex regex. It can be simpler (less code) and faster, like /\s_cke_saved_src\s*=/.

Changed 4 years ago by Saare

comment:13 Changed 4 years ago by Saare

  • Status changed from review_failed to review

comment:14 Changed 4 years ago by jcai

Thanks Saare, but this patch doesn't fix the problem either.

comment:15 Changed 4 years ago by Rick

The same problem with "href" attribute (<a> tag). Tried to apply patch, but it doesn't help :(

comment:16 Changed 4 years ago by tobiasz.cudnik

  • Status changed from review to review_passed

I'm giving R+ as ticket issue is fixed. If you're having similar issues with other attributes please open a new ticket for them.

comment:17 Changed 4 years ago by Saare

  • Status changed from review_passed to closed
  • Resolution set to fixed

Fixed with [5878].

comment:18 Changed 4 years ago by rocing

Problems still exist

comment:19 Changed 4 years ago by Saare

#6320 is a DUP.

comment:20 Changed 4 years ago by jonathonsim

Unfortunately, I can still reproduce this problem on the nightly build using firefox 3.6.10

The url of the pasted image becomes <img src="../../test/fake.gif">

comment:21 Changed 4 years ago by alfonsoml

The problems with latests Firefoxes is #6275

Note: See TracTickets for help on using tickets.
© 2003 – 2012 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy