31 December, 2011

Umbraco 4.7.1.1 macro parameter bug

Using the same xslt macro twice on pages causes invalid attribute values.

The bug in Umbraco 4.7.1.1 causes the parameters of following requests to load invalid or wrong parameters. The bug was discovered in the process of upgrading from version 4.5.2, and it took some time to find due to the change in loading macros in Umbraco.

How to re-produce the bug:
Load two or more macros on the same page, adding some attributes to the macro in Umbraco. If the first macro does not use all the properties (default empty values) the second macro usage will cache and set the attributes on the following requests.

This will cause rendering of invalid content....!!!

In my case it was a menu macro with an attribute defining which node to use as start node for rendering, if not set the xslt macro would use the site's rootNode/defaultNode as the start node. But this bug caused the macro to load a wrong content tree as the menu :-(

The fix is to change/update the UpdateMacroModel method code to the folowing, in the umbraco.presentation.macro.cs file:
public void UpdateMacroModel(Hashtable attributes)
        {
            foreach (MacroPropertyModel mp in Model.Properties)
            {
    if (attributes.ContainsKey(mp.Key.ToLower()))
    {
     mp.Value = attributes[mp.Key.ToLower()].ToString();
    }
    else
    {
     mp.Value = string.Empty;
    }
            }
        }
I have submitted a post here: http://our.umbraco.org/forum/developers/xslt/21851-All-XSLT-files-suddenly-giving-error-parsing-XSLT-file?p=2#comment101528

And added a diff file to umbraco's codeplex site: http://umbraco.codeplex.com/workitem/30657

1 comment:

  1. Excellent spotted - I've committed your fix to the core!

    ReplyDelete