href attribute is removed while saving the text in the RTE component | Community
Skip to main content
Level 2
June 3, 2022

href attribute is removed while saving the text in the RTE component

  • June 3, 2022
  • 4 replies
  • 2455 views

Hi All,

I have created a custom plugin to add some html code (i.e. once we select a word and click on the tool button created as part of new plugin). Example:

'<a title="we-retail alt" href="/content/we-retail/us/en.html" target="_blank">discovery</a>'

After adding this I can see this on RTE component dialog.

 

Once I close (save) the dialog the added href is removed.

and on View Source it is coming like this:

<a title="we-retail alt" target="_blank">discovery</a>

I am using AEM 6.5.12

 

Can you please tell me the root cause here and how to resolve this issue?

To me it looks like RTE limitation for security purpose.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

RajaShankar
Community Advisor
Community Advisor
June 3, 2022

Hi @maans 

Did you tried with the link icon for hyperlink of text

https://experienceleague.adobe.com/docs/experience-manager-core-components/using/components/text.html

Please check and let us know how it behaves in your case.

 

Regards,

Rajashankar.R

 

maansAuthor
Level 2
June 6, 2022

Hi @rajashankar ,

Link plugin is working as expected. But in my plugin when I am trying to add a href attribute in <a> tag. In this case, href is removed while saving the RTE.

Error logs:

06.06.2022 11:42:05.265 *ERROR* [sling-default-3-com.day.cq.rewriter.linkchecker.impl.LinkCheckerTask.7176] com.day.cq.rewriter.linkchecker.impl.LinkCheckerTask Failed to validate URL http://www.adobe.com/go/aem6_5_activation: java.net.SocketException: Connection reset
06.06.2022 11:42:25.381 *INFO* [sling-default-3-com.day.cq.rewriter.linkchecker.impl.LinkCheckerTask.7176] org.apache.http.impl.execchain.RetryExec I/O exception (java.net.SocketException) caught when processing request to {s}->https://business.adobe.com:443: Connection reset
06.06.2022 11:42:25.381 *INFO* [sling-default-3-com.day.cq.rewriter.linkchecker.impl.LinkCheckerTask.7176] org.apache.http.impl.execchain.RetryExec Retrying request to {s}->https://business.adobe.com:443
06.06.2022 11:42:31.011 *WARN* [[0:0:0:0:0:0:0:1] [1654495951006] POST /content/wbg/us/en/testpage0/_jcr_content/root/twit_text HTTP/1.1] com.adobe.cq.wcm.core.components.internal.servlets.DMAssetPostProcessor Last file reference modification was null for 'fileReference' property name.

 

Thanks

arunpatidar
Community Advisor
Community Advisor
June 3, 2022

Hi,

this can’t be the limitation as link(a tag) needed href. It works with out of the box link plugin, so it should work here as well, can you try adding OOTB link plugin just for test and check. 

 

Arun Patidar
maansAuthor
Level 2
June 6, 2022

Hi,

Link plugin is working as expected. But in my plugin when I am trying to add a href attribute in <a> tag. In this case, href is removed while saving the RTE.

Error logs:

06.06.2022 11:42:05.265 *ERROR* [sling-default-3-com.day.cq.rewriter.linkchecker.impl.LinkCheckerTask.7176] com.day.cq.rewriter.linkchecker.impl.LinkCheckerTask Failed to validate URL http://www.adobe.com/go/aem6_5_activation: java.net.SocketException: Connection reset
06.06.2022 11:42:25.381 *INFO* [sling-default-3-com.day.cq.rewriter.linkchecker.impl.LinkCheckerTask.7176] org.apache.http.impl.execchain.RetryExec I/O exception (java.net.SocketException) caught when processing request to {s}->https://business.adobe.com:443: Connection reset
06.06.2022 11:42:25.381 *INFO* [sling-default-3-com.day.cq.rewriter.linkchecker.impl.LinkCheckerTask.7176] org.apache.http.impl.execchain.RetryExec Retrying request to {s}->https://business.adobe.com:443
06.06.2022 11:42:31.011 *WARN* [[0:0:0:0:0:0:0:1] [1654495951006] POST /content/wbg/us/en/testpage0/_jcr_content/root/twit_text HTTP/1.1] com.adobe.cq.wcm.core.components.internal.servlets.DMAssetPostProcessor Last file reference modification was null for 'fileReference' property name.

 

Thanks

SantoshSai
Community Advisor
Community Advisor
June 3, 2022

Hi @maans ,

Agree with @arunpatidar - As it's working absolutely fine with OOTB. 

 



Please check your custom plugin or try adding a same plugin (which is available OOTB) and check it should work.

Regards,
Santosh

Santosh Sai
maansAuthor
Level 2
June 13, 2022

Hi All,

 Thanks for your replies. I have not found the solution yet. I have followed the link: http://experience-aem.blogspot.com/2019/04/aem-65-touch-ui-rte-rich-text-editor-structured-content-plugin-creating-tooltips.html

 

Here, I have modified function getHtmlFromContent() for my own customized tool.

 

var vhref = "https://twitter.com/";
vhref = Granite.URITemplate.expand("{+path}", {"path" : vhref});
vhref = vhref.replace(/'/g, '%27');
return "<span class='abcd' data-content='"+ JSON.stringify(content)+"' " + "'><a href='" + vhref +"' class='twd-id' aria-label='text'>"+selectedText+"</a></span>";

 

line 1, 2  and 3 are added by analyzing the file: /libs/cq/gui/components/authoring/rte/coralui3/js/RTE.CQLinkPlugin.js 

I am not sure what else is missing from the code.  Here I am using  ek.execCmd('inserthtml', tooltipHtml);

to insert the html. I can see the html is inserted before saving the RTE text field, Once RTE is saved href attribute is removed from the source code.

 

Any pointers will surely help.

 

Thanks,

Manasi

maansAuthor
Level 2
June 16, 2022

Hi All,

Finally issue is resolved. I was getting antisamy error.

Solved using _rte_href with href.

return "<span class='abcd' data-content='"+ JSON.stringify(content)+"' " + "'><a href='" + vhref +"'" + " _rte_href='" + vhref + "' " + "class='twd-id' aria-label='text'>"+selectedText+"</a></span>";
}

 

Thanks