Expand my Community achievements bar.

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

Avatar

Level 2

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.

maans_0-1654265814889.png

 

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.

 

7 Replies

Avatar

Community Advisor

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.htm...

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

 

Regards,

Rajashankar.R

 

Avatar

Level 2

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

Avatar

Community Advisor

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

Avatar

Level 2

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

Avatar

Community Advisor

Hi @maans ,

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

 

Screen Shot 2022-06-03 at 7.29.51 PM.png

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

Regards,
Santosh

Avatar

Level 2

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-p...

 

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

Avatar

Level 2

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