Layout.Title is being encoded... twice?

Topics: Troubleshooting
Jul 6, 2011 at 10:11 AM


I noticed that Layout.Title is being encoded twice in most places of Orchard. For example, in the Contents Edit view (Core\Contents\Views\Admin\Edit.cshtml), we find the following code:

pageTitle = T("Edit {0}", typeDisplayName);
// ...
Layout.Title = pageTitle;

The use of the T localizer causes its arguments to be encoded (in Orchard.Localization.Text), and then the whole text is encoded again when displayed in the header (Themes\TheAdmin\Views\Layout.cshtml). This causes issues a double encoding issue that causes an apostrophe character to appear as "'".

This pattern is recurrent throughout Orchard. I wonder whether it was mistakenly forgotten or just deemed unimportant? Is there a fix for this somewhere (e.g. in the dev branch)?

Jul 6, 2011 at 1:50 PM

Hmm ... seems to me like a slight flaw in localization. Intuitively, localization shouldn't involve any encoding; you could be localizing strings for purposes other than HTML (for instance, sending a plain-text email). On the other hand, I've seen instances where T(..) calls included actual HTML markup, e.g. "<b>", which in itself seems a bit wrong. Localization should be output-agnostic, but it seems hard to decouple with some of the current usages. I would say this needs a workitem raising.

Jul 6, 2011 at 11:11 PM

By design, T returns an HtmlString so that one can have localizable strings with perfectly valid semantic markup such as "This here: <strong>{0}</strong> is important." No, localization should not be output-agnostic, I can't see a good justification of that.

An HtmlString should never get double-encoded (that's kind of the point), and I wasn't able to reproduce the problem you're exposing. What theme were you using?

Jul 10, 2011 at 9:16 AM
Edited Jul 10, 2011 at 9:19 AM

Sorry I wasn't clear enough. I'm not using any special themes; just the normal dashboard (version 1.2.41).

If the type's display name contains a special character (e.g. an apostrophe), the content editing page shows that character encoded twice. It is also possible to see it if you create a list with a special character in its name (e.g. "Author's List"). After you save the list, the "Manage List" page is shown with the special characters encoded twice (e.g. "Author&#39;s List").

Jul 11, 2011 at 8:54 PM

Ah, OK, I see. Can you please file a bug?