Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#5218 closed Bug (fixed)

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

Reported by: Omkar Owned by: Sa'ar Zac Elias
Priority: Normal Milestone: CKEditor 3.4.1
Component: Core : Pasting Version: 3.1
Keywords: HasPatch Cc: Vincent, 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 (4)

ckEditorFFBug.png (88.1 KB) - added by Omkar 14 years ago.
Screenshot of the URL being modified in Firefox 3.5.8
5218.patch (1.4 KB) - added by Jonathon Sim 14 years ago.
Fixed version of the patch
5218.2.patch (1.4 KB) - added by Sa'ar Zac Elias 14 years ago.
5218_3.patch (1.4 KB) - added by Sa'ar Zac Elias 14 years ago.

Download all attachments as: .zip

Change History (25)

Changed 14 years ago by Omkar

Attachment: ckEditorFFBug.png added

Screenshot of the URL being modified in Firefox 3.5.8

comment:1 Changed 14 years ago by laurentl

Component: GeneralCore : 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 14 years ago by Alfonso Martínez de Lizarrondo

Cc: Vincent added

#5665 has been marked as dup

comment:3 Changed 14 years ago by Jonathon Sim

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 14 years ago by Jonathon Sim

Attachment: 5218.patch added

Fixed version of the patch

comment:4 Changed 14 years ago by Jonathon Sim

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 14 years ago by Frederico Caldeira Knabben

Keywords: Confirmed added
Milestone: 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 14 years ago by Jonathon Sim

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 14 years ago by Frederico Caldeira Knabben

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 14 years ago by Charlie

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 14 years ago by Tobiasz Cudnik

Keywords: HasPatch added
Owner: set to Tobiasz Cudnik
Status: confirmedassigned

Changed 14 years ago by Sa'ar Zac Elias

Attachment: 5218.2.patch added

comment:10 Changed 14 years ago by Sa'ar Zac Elias

Owner: changed from Tobiasz Cudnik to Sa'ar Zac Elias
Status: assignedreview

comment:11 Changed 14 years ago by Tobiasz Cudnik

Status: reviewreview_passed

comment:12 Changed 14 years ago by Frederico Caldeira Knabben

Status: review_passedreview_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 14 years ago by Sa'ar Zac Elias

Attachment: 5218_3.patch added

comment:13 Changed 14 years ago by Sa'ar Zac Elias

Status: review_failedreview

comment:14 Changed 14 years ago by Joe

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

comment:15 Changed 14 years ago by Rick

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

comment:16 Changed 14 years ago by Tobiasz Cudnik

Status: reviewreview_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 14 years ago by Sa'ar Zac Elias

Resolution: fixed
Status: review_passedclosed

Fixed with [5878].

comment:18 Changed 14 years ago by rocing

Problems still exist

comment:19 Changed 14 years ago by Sa'ar Zac Elias

#6320 is a DUP.

comment:20 Changed 14 years ago by Jonathon Sim

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 14 years ago by Alfonso Martínez de Lizarrondo

The problems with latests Firefoxes is #6275

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy