Quite often I come across JS code snippets which are embedded in HTML comments:
<script type="text/javascript"><!--
// some JS code
//--></script>
Now and then web developers forget to add the closing comment marker:
<script type="text/javascript"><!--
// some JS code
</script>
Firefox etc. seems to implicitly close the comment at the end of the script block. What happens when run with HtmlUnit depends on the content that follows. Imagine there is another comment somewhere below the script block:
<script type="text/javascript"><!--
// some JS code
</script>
<h1>some text</h1>
<!-- some comment -->
In this case, the script block is extended up to the end of the page and then auto-closed. Usually, this results in JS errors later on, as the HTML code that follows will be part of the script body.
Interestingly, if there is no such comment below the script block, everything works as smooth as in Firefox!?
Since JS errors do not result in exceptions by default, such a missing comment marker can be hard to spot. It would be great if HtmlUnit could auto-close open comments in all cases.
test case
Note that IE (6-8) isn't lenient for this case.
Unit test added (as NotYetImplemented): HTMLParser2Test.unclosedCommentsInScript
Diff: