Umbraco-cms: Textarea Macro Parameter Not Rendering HTML Markup

Created on 5 Sep 2019  路  7Comments  路  Source: umbraco/Umbraco-CMS

In Umbraco v8, I am inserting a macro into the grid editor.

I am using a macro to embed a hubspot form code into a parameter that is a textarea called embed.

The macro itself just renders the embed code in the parameter like so: @Html.Raw(Model.MacroParameters["embed"])

The output of this is literally printing the html markup that I put into the macro parameter.

If I output just the parameter _without_ Html.Raw then I get the decoded markup printed out. ( & instead of "&")

When I tested just entering this macro into the RTE, the macro disappears on save.

I was able to do this in previous versions of Umbraco just fine but it seems that I can no longer do this in v8. I posted this on our as well.


_This item has been added to our backlog AB#2540_

typbug

Most helpful comment

@bkclerke the macro parameter value is stored encoded and hence when you use the @Html.Raw(..) it renders the html mark up. As a workaround i tried performing a decode before passing it onto the Raw function and i was able to render the HTML form. Below is the code i used.
@Html.Raw(System.Web.HttpUtility.HtmlDecode(Convert.ToString(Model.MacroParameters["embed"])))

PS:Not a good one, but might able to help you until the bug is resolved.

I couldn't manage to get the backoffice showing the form render but the webpage shows it right.

Hope this helps.

All 7 comments

Thanks @bkclerke - I can reproduce the error. Now to find the cause... 馃檲

@bkclerke the macro parameter value is stored encoded and hence when you use the @Html.Raw(..) it renders the html mark up. As a workaround i tried performing a decode before passing it onto the Raw function and i was able to render the HTML form. Below is the code i used.
@Html.Raw(System.Web.HttpUtility.HtmlDecode(Convert.ToString(Model.MacroParameters["embed"])))

PS:Not a good one, but might able to help you until the bug is resolved.

I couldn't manage to get the backoffice showing the form render but the webpage shows it right.

Hope this helps.

It looks like the attribute values need to be decoded in either RteMacroRenderingValueConverter.RenderRteMacros or MacroTagParser.ParseMacro, I'm not sure if there's any reason to prefer one over the other.

The thing I'm afraid of now is when we do fix this that workarounds like the one above are going to break your site(s) 馃

Or maybe double-decoding could work fine. Not sure.

@nul800sebastiaan double decoding works, doesn't break. If it doesn't find anything to decode,it just returns the string as is.

That depends what the original parameter value was. If it was HTML containing encoded things, double decoding could break it.

It could also be a breaking change if people are unknowingly relying on the HTML encoding for other parameters that don't contain HTML. You might have written @Html.Raw(Model.MacroParameters["title"]) because @Model.MacroParameters["title"] was coming out double-encoded, without really recognising that this was a workaround for a bug.

Thank you!! && @gopkumr thank you for the work around! I've actually hard coded the form for now since the site is launching on Tuesday. I'll definitely be keeping an eye out for fixes though, I plan to upgrade the site and I can add this macro back in for future features. :)

Was this page helpful?
0 / 5 - 0 ratings