This is a migrated thread and some comments may be shown as answers.

Copy and Paste Bug with Relative Link HREFs starting with /

1 Answer 83 Views
Editor
This is a migrated thread and some comments may be shown as answers.
mattzilla
Top achievements
Rank 1
mattzilla asked on 14 May 2010, 01:48 AM
I've discovered a bug with RadEditor when copying and pasting a link, where the link's href starts with a slash. In Firefox, the pasted link is preceded by any number of ../ and part of the path removed, and in IE, the link is changed to an absolute path including the domain.

Steps to reproduce.

  1. Visit: http://demos.telerik.com/aspnet-ajax/editor/examples/default/defaultcs.aspx
  2. In the first paragraph, change the Sharepoint link's href to: /products/aspnet-ajax/sharepoint.aspx
  3. Copy the paragraph
  4. Paste the paragraph somewhere else in the editor
  5. View the new href of the Sharepoint link in the pasted paragraph

Results

Firefox
Link href becomes: ../../../../products/aspnet-ajax/sharepoint.aspx

IE
Link href becomes: http://demos.telerik.com/products/aspnet-ajax/sharepoint.aspx

Expected result:

Link to remain as /products/aspnet-ajax/sharepoint.aspx

Regards

Matt

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 14 May 2010, 04:03 PM
Hi Matt,

This is a browser related behavior not related to RadEditor's source code.

When copying and pasting a link or an image with a relative path in Internet Explorer, the browser automatically converts the path to absolute. The code below demonstrates how to attach to the OnClientPasteHtml event and strip the desired url path using the StripPathFilter content filter. The StripPathsFilter() method receives as a parameter an array of strings (devided by a white space) that will be stripped from the absolute path.

<script type="text/javascript">
function OnClientPasteHtml(sender, args)
{
    var commandName = args.get_commandName();
    var value = args.get_value();
    
    if (commandName == "Paste")
    {
       // The StripPathsFilter() method receives as a parameter an array of strings (devided by a white space) that will be stripped from the absolute links.
        var domainName = "http://" + window.location.host; //returns the hostname and port number of the current URL
        var filter = new Telerik.Web.UI.Editor.StripPathsFilter([domainName]); //strip the domain name from the absolute path
                    
        var contentElement = document.createElement("SPAN");
        contentElement.innerHTML = value;
        var newElement = filter.getHtmlContent(contentElement);
        alert(newElement.outerHTML);
        args.set_value(newElement.outerHTML);  //set the modified pasted content in the editor
    }
}
</script>

Please, note that the OnClientPasteHtml event fires the Paste command only when the StripFormattingOnPaste property is not set to "NoneSupressCleanMessage". In this case the editor does not process the pasted content and pastes it without modifications.

The information above is taken from the description of the OnClientPasteHtml demo.


All the best,
Rumen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Editor
Asked by
mattzilla
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or