Script tags with custom scripts get HTML encoded
kevindeyne opened this issue · 2 comments
kevindeyne commented
An HTML with the following:
<script>
//redirect script once loaded - should eventually be a Medusa feature
var _M = _M || {};
_M.postRender = function (incomingMessage) {
if(incomingMessage !== null && typeof incomingMessage !== "undefined" && incomingMessage.length === 1) {
if("redirect" === incomingMessage[0]['f']) {
window.location.href = incomingMessage[0]['v'];
}
}
};
</script>
Turns into
<script>
//redirect script once loaded - should eventually be a Medusa feature
var _M = _M || {};
_M.postRender = function (incomingMessage) {
if(incomingMessage !== null && typeof incomingMessage !== "undefined" && incomingMessage.length === 1) {
if("redirect" === incomingMessage[0]['f']) {
window.location.href = incomingMessage[0]['v'];
}
}
};
</script>
dirkdeyne commented
An easy workaround is to mix JS-comment //
and CDATA
.
The XML-Parser treats the CDATA-section as regular text, and JS just sees the extra lines as comments.
<script>
// <![CDATA[
//redirect script once loaded - should eventually be a Medusa feature
var _M = _M || {};
_M.postRender = function (incomingMessage) {
if(incomingMessage !== null && typeof incomingMessage !== "undefined" && incomingMessage.length === 1) {
if("redirect" === incomingMessage[0]['f']) {
window.location.href = incomingMessage[0]['v'];
}
}
};
// ]]-->
</script>