#14988xhtml_cleaning corrupts javascript in HTML-comment from extension
Description
in my extension I want to write some javascript like:
$content.=‘
<script type="text/javascript"><br /><!--<br />function count_to(j) {<br /> var s="";<br /> for (var i=0; i<j; i++ ) {<br /> s+=i+" ";<br /> }<br /> alert(s);<br />}<br />count_to(10);<br />//--><br /></script>‘;
what ends up in the HTML-source of the resulting page is:
<script type="text/javascript"><br /><!--<br />function count_to(j) {<br />var s="";<br />for (var i=0; i<j; i="" s="i+"" alertscount_to10--=""><br /></script>
it seems that the cleaning is done inside of the HTML-comment.
Especially the ‘<’ in the loop-header is mis-interpreted as an opening HTML-tag and anything following as parameter to this tag.
unsetting
page.config.xhtml_cleaning = all
leaves all javascript ok.
my workaround for this small part of code is using
for (var i=0; j>i; i++ ) {
instead of
for (var i=0; i<j; i++ ) {
But I think it can go worse if in the javascript a ‘<’ is needed in a string.
BTW: I prepare the proper javascript-code with infos from within PHP, so I can’t include the javascript from extern.
(issue imported from #M1477)
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.