Bug reports Found a bug? Post it here please.
Version 6.x > Bug reports > Html editor intermittently saves double-encoded data View modes: 
User avatar
Member
Member
greatbritishchefs - 10/14/2013 10:34:00 AM
   
Html editor intermittently saves double-encoded data
Hi

We are having a problem (on our Kentico award-winning site!) where intermittently we are finding html blocks on the site (originating from HTML fields on content item forms) with double encoded markup i.e. the user sees the markup rather than what the markup is describing. When this has happened to me, investigation showed that there was double-encoded data in the hidden text area of the HTML editor. It didn't seem to be connected to loss of connection or session, which was my initial thought.

We're running v6.0.21 on win server 2008 r2 (Amazon).

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 10/15/2013 3:08:42 AM
   
RE:Html editor intermittently saves double-encoded data
Hi,

Thank you for your message.

May I ask if this happened before or it started occuring out of nothing? Can you recall any changes to your site when it started happening?

Also would it be possible for you to post here some screenshots so we get a better idea of how does it look.

Thank you for more information.

Kind regards,
Richard Sustek

User avatar
Member
Member
greatbritishchefs - 10/17/2013 7:28:59 AM
   
RE:Html editor intermittently saves double-encoded data
Hi Richard

This has always been an issue for us. Here are screenshots of the site and the page in the CMS editor/form tab. Interestingly, in the CMS it is correctly displayed. The page is fully published, and the Page tab in the CMS also shows the double-encoding like the site.

On CMS

User image

On Site

User image

User avatar
Member
Member
greatbritishchefs - 10/17/2013 8:03:11 AM
   
RE:Html editor intermittently saves double-encoded data
Be nice to have a forum with image uploads... Those are stuck behind the security of the server I uploaded them to so try these.

Site

User image

CMS

User image

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 10/18/2013 2:10:21 AM
   
RE:Html editor intermittently saves double-encoded data
Hi,

Thank you for additional information. This is quite unusual issue.

I would ask some questions: What webpart are you using? Is this happening on all pages?

Can you try adding a new webpart to the page as Editable text and insert some formatted text into it?

How does it work?

Kind regards,
Richard Sustek

User avatar
Member
Member
greatbritishchefs - 10/18/2013 4:46:10 AM
   
RE:Html editor intermittently saves double-encoded data
Hi Richard

The webpart which is displaying the double-encoded output is a repeater, so it is being retrieved from the field in a transformation. However, if we look in the database at the field containing the data, only this record's field has encoded html e.g. '<div>' rather than plain html '<div>', which means the problem is when the data is saved not output.

This can potentially happen on any page on the site where there is html input, which is across a number of templates.

This gives me the impression it is the HTML editor in the CMS UI which is having the problem, specifically I suspect it is to do with a synchronisation failure between the display iframe and the backing hidden textarea. I had suspected it might be caused by loss of connection or session, but I have experienced this issue myself when both were fine.

Using editable text will not be a solution for us as we have many templates with html fields input on forms and to change this would involve reengineering the whole site and retraining content staff. In any case, the above would indicate that because editable text uses the same html editor as form input (as far as I can tell) the problem would persist. Furthermore, we could test the editable text for quite a long time and it might not show this issue as it is quite intermittent.

Thanks for your help
James

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 10/18/2013 4:58:51 AM
   
RE:Html editor intermittently saves double-encoded data
Hi,

Can you post the transformation you are using?

Also when you are retrieving data could you try using something like:

<%# Eval("field", false) %>


Does this helps?

Kind regards,
Richard Sustek

User avatar
Member
Member
greatbritishchefs - 10/18/2013 5:32:29 AM
   
RE:Html editor intermittently saves double-encoded data
The transformation was already using
<%# Eval("field") %>

I've added the 'false' parameter but this has made no difference. It seems unlikely to me that the transformation has anything to do with it because as I mentioned, the problem is there in the the database and so it must be a problem with saving rather than displaying.

FYI the full transformation is as now edited follows:


<%@ Register TagPrefix="gbc" TagName="ShareThis" Src="~/CMSWebParts/GBC/ShareThis.ascx" %>
<%@ Register TagPrefix="gbc" TagName="DFPAdTag" Src="~/CMSWebParts/GBC/DFPAdTag.ascx" %>
<header class="content-header share-header how-to-header">
<h1><%# Eval("HowToTitle") %></h1>
<div class="badge">
<gbc:DFPAdTag ID="dfpBadge" runat="server" Width="100" Height="80" AdUnitName="badge" />
</div>
<gbc:ShareThis id="uscShareThis" runat="server"/>
<div style="clear:both"></div>
</header>

<asp:Panel id="pnlhowtocookarticle" runat="server" Visible=<%# Eval("Article").ToString() == "True" ? true : false %>>
<%# Eval("ArticleBody", false) %>
</asp:Panel>

<asp:Panel id="pnlhowtocookvideo" runat="server" Visible=<%# Eval("Article").ToString() == "False" ? true : false %>>
<p class="intro">
<%# Eval("HowToIntro", false) %>
</p>
<div class="et-content">
<%# Eval("HowToWistiaCode") == DBNull.Value || (Eval("HowToWistiaCode") as string) == "" ? Eval("HowToVimeoCode") : Eval("HowToWistiaCode") %>
</div>
<asp:PlaceHolder id="phEventScript" runat="server" Visible='<%# Eval("HowToWistiaCode") != DBNull.Value %>'>
<script type='text/javascript'>
wistiaEmbeds.onFind(function(video){
video.bind("play", function(){
_gaq.push(['_trackEvent', 'Video', 'Play', video.name()]);
return this.unbind;
}).bind("end", function(){
_gaq.push(['_trackEvent', 'Video', 'Complete', video.name()]);
return this.unbind;
});
});
</script>
</asp:PlaceHolder>

<p class="intro">
<%# Eval("HowToTextBelowVideo") %>
</p>


<!--<div class="adbanner noprint">
<gbc:DFPAdTag ID="dfpInPageTop" runat="server" Width="640" Height="80" AdUnitName="inpagetop" />
</div>-->



<%# Eval("HowToSteps") %>
</asp:Panel>

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 10/22/2013 4:37:07 AM
   
RE:Html editor intermittently saves double-encoded data
Hi,

That is quite strange. Can you please check the database and tell in which format is it saved? Are the tags encoded or not?

In my instance the tags are not being encoded. We are not aware of any issues with encoding can you recall anything you changed/customized or anything that could help clarify this?

Can you also try this on our sample corporate site which you can easily install in Site manager -> sites?

Kind regards,
Richard Sustek

User avatar
Member
Member
greatbritishchefs - 10/22/2013 5:44:48 AM
   
RE:Html editor intermittently saves double-encoded data
Hi

You may notice that I mentioned before that the tags are encoded in the database. This is an intermittent problem though, so for the vast majority of records the tags are not encoded, the tags are only encoded on records where we can see the problem when we look at the live site. If I look at an example database field where this happens, 11 out of 1100 records have the issue.

Sorry I don't have time to install an entire new CMS site and then repeatedly enter data into it until I've done so enough times to be sure whether or not an intermittent fault is occurring unless you have some very strong reason to think this will help, and it will give you more than vaguely suggestive information about what the issue is.

Thanks for continuing to investigate this.

James

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 10/22/2013 8:02:21 AM
   
RE:Html editor intermittently saves double-encoded data
Hi James,

I'm not sure how it could get saved encoded, this is not the way of how we store data in document types.

The creation of Corporate site takes only about a 2 minutes. You can easily create it through our wizard in Site manager -> Sites.

However I managed to bypass this and found out resolution.

What you need is to create a custom transformation function as per: http://devnet.kentico.com/docs/devguide/adding_custom_functions_to_transformations.htm?zoom_highlightsub=adding%2Bfunctions%2Bto%2Btransformation

The function will look like:

public string DecodeHtml(object html)
{
string htmlCode = (string)html;
return HttpUtility.HtmlDecode(htmlCode);
}


And then you can simply call it in transformation like:

DecodeHtml(Eval("NewsSummary"))


Please let me know how this works for you.

Kind regards,
Richard Sustek

User avatar
Member
Member
greatbritishchefs - 10/28/2013 10:13:43 AM
   
RE:Html editor intermittently saves double-encoded data
Hi Richard

Thanks for keeping with this. I was about to try this when I realised that it won't work because you want to preserve encoding in texts which are not affected by this bug. For instance, if you have the character '<' in the text you enter into the editor, it will be correctly encoded to < int the database for insertion into html. If I then decode this, it will be treated as malformed html and display wrongly. Intuitively you might expect this fix would have some negative effects as it is a 'cheat' in some way, not a proper resolution of the issue.

Do you have any other ideas?

best wishes

James

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 10/29/2013 11:29:53 PM
   
RE:Html editor intermittently saves double-encoded data
Hi James,

You're welcome,this is the only possible solution here. If your database is inconsistent is this way you will have to manually "repair" it. So the only thing that comes to my mind right is to have manually decode your fields in database (using e.g. some online tool) and then resaving the decoded value and therefore it will be consistent and should display fine.

Kind regards,
Richard Sustek

User avatar
Member
Member
greatbritishchefs - 10/18/2013 4:50:30 AM
   
RE:Html editor intermittently saves double-encoded data
Sorry the html editor on the forum didn't double-encode the first markup example I gave above!

It should have read:
encoded html e.g. '&lt;div&gt;' rather than plain html '<div>'