This project is read-only.

[WI #18798] Admin menu item double encoded ?

Topics: Core
Jul 10, 2012 at 11:03 AM

I'm trying to understand why admin menu items are double encoded.

See here :

In DB, everything is correct : Navigation_AdminMenuPartRecord table has one record with raw text.

In TheAdmin/Views/Menu.cshtml everything seems to be fine, but if I set a breakpoint on "string sectionHeaderText = firstLevelMenuItem.Text.Text;" the title "Actualités" is already HTML encoded, so the rest of the code is correct...

I'm trying to understand where the text is encoded (it's certainly on the shape build).

Jul 10, 2012 at 11:11 AM

It seems that the problems resides in "AdminMenuNavigationProvider.cs" in Navigation\Services : the menuitem is encoded before being added in NavigationBuilder.

public void GetNavigation(NavigationBuilder builder) {
    var menuParts = _contentManager.Query<AdminMenuPart, AdminMenuPartRecord>().Where(x => x.OnAdminMenu).List();
    foreach (var menuPart in menuParts) {
        if (menuPart != null) {
            var part = menuPart;

            builder.Add(new LocalizedString(HttpUtility.HtmlEncode(part.AdminMenuText)),
                        item => item.Action(_contentManager.GetItemMetadata(part.ContentItem).AdminRouteValues));
            // todo: somehow determine if they will ultimately have rights to the destination and hide if not. possibly would need to add a Permission to metadata.
            // todo: give an iconset somehow (e.g. based on convention, module/content/<content-type>.adminmenu.png).
If I remove the HmlEncode() everything render fine.

Jul 10, 2012 at 2:55 PM

Please file a bug.

Jul 10, 2012 at 3:08 PM

Done :

I've made a (trivial) fix available as pull request here :