HTML markup in activation alert of Magnolia CMS

I recently ran into a problem I’d like to quickly outline in this post. At some point after activating a page in Magnolia the activation alert started to display HTML markup appended to the activation message. The activation alert looked like this:

Activation Alert

Magnolia CMS activation alert

After some diving into the frontend code we found the lines where the error got triggered. The problem came from the function mgnlAlertCallbackMessage(html) in the tree.js which tries to extract the activation message from the html markup.

function mgnlAlertCallbackMessage(html) {
 var messagePattern = '<input type="hidden" id="mgnlMessage" value="';
 // check if alert message was sent back
 if (html.indexOf(messagePattern) != -1) {
 var start = html.indexOf(messagePattern);
 var end = html.indexOf("\" />", start);
 var msg = html.slice(start + messagePattern.length, end);
 alert(msg);
 html = html.slice(end);
 }
 return html;
}

First this function gets the start index, which is 0, and then tries to get the end index with the help of the end tag markup which is defined like this:

" />

Unfortunately the Apache module mod_pagespeed strips unnecessary whitespace from the html source. And exactly this end tag markup which the javascript is looking for, contains such an unnecessary whitespace. So after mod_pagespeed runs through the code the end tag looks like this:

"/>

The problem now is that the function mgnlAlertCallbackMessage(html) can’t retrieve the end index of the input tag, meaning it results in -1. Therefore the slice function doesn’t slice the string but takes the whole string starting at the previously fetched start index.

I’d say that disabling the whitespace filter in the mod_pagespeed.conf would be enough:

#ModPagespeedEnableFilters collapse_whitespace

but unfortunately it didn’t work for me. I had to disable the whole module with:

ModPagespeed off