Search code examples
htmlspecial-charactersligature

Stored Ligature HTML is not rendering


I am using GroupDocs Viewer to take a PDF and create a HTML page for it. I store the HTML in a nvarchar(MAX) field in my SQL2012 database. I just learned today during some testing that we're having some special characters (ligatures) in the documents not rendering correctly.

Question Marks are highlighted only to make them easy to find.

These Ligatures(fl, fi, ff) are missing for some reason. I checked my database and they seem to be stored there correctly.

I checked the JsonResult server method I'm using to load the page and I'm getting some mixed results trying to determine if my pageHtml string has the char.

public async Task<JsonResult> LoadDocument(int contentID, int page)
{
    try
    {
        var documentPageData = await APIAccess.Get<DocumentPageUserData>(DocumentPageData.GetDocumentPageRoute, contentID, CurrentUser.UserID, page);

        JsonResult result = new JsonResult()
        {
            ContentEncoding = Encoding.Default,
            ContentType = "application/json",
            Data = new
            {
                pageHTML = documentPageData.DocumentPage.PageHtml //.Replace("?", "fl").Replace("?", "fi").Replace("?", "ff")      //Don't like this idea
            },
            JsonRequestBehavior = JsonRequestBehavior.AllowGet,
            MaxJsonLength = int.MaxValue
        };

        return result;
    }
    catch (Exception ex)
    {
        return Json(string.Format("There was an error loading the page.\r\n\r\nDetails:\r\n{0}", ex.Message),
            JsonRequestBehavior.AllowGet);
    }
}

When I mouse over DocumentPage.Html and ask to render it as HTML, it looks great. The Text Render has a <span>?</span>however. Not sure if that's just because the Text Render doesn't have a font or if there is another problem.

On the Client side I store the html text in session storage until the page is requested then I render it into a div like so.

 var externalHtml = sessionStorage.getItem(currentPage);
 $('.viewer').text('');
 $('.viewer').append(externalHtml);

I've tried checking the network traffic and the client side html but it looks like it has ? so I'm not sure where I'm loosing my characters. Any ideas?


Solution

  • The JsonResult was not being encoded properly. I changed ContentEncoding = Encoding.Default to ContentEncoding = Encoding.UTF8. After that it rendered perfectly. Sigh... Been working on this for 2.5 days.