When getting the inner HTML of the document body and afterwards setting the received content again as inner HTML, the text content of any contained script element (maybe style as well) will be HTML encoded. This is in contrast to Firefox and Co. See the attachment for an example. Thanks for your help!
And here is a tiny test case that demonstrates this issue.
I had a look at the code. It appears that when getting the inner HTML from an element, the code does already check whether the element is a script (or style) element and disables HTML escaping in this case. However, it makes this decision only once, based on the type of the root element. So for the script element's content being escaped or not, it makes a difference whether innerHTML is queried for the script element directly (no escaping) or the surrounding body element (script content escaped).
I have exactly the same problem. I am generating dynamic content based on templates defined inside inline script elements.
Last edit: PabloGDT 2013-10-02
I don't understand the comparison with FF here: asXml() is specific to HtmlUnit, and it has to use entities to produce valid xml.
What I can see, is that innerHTML is in sync with FF when called on the script node, but not for instance on the body.
The behavior of HtmlUnit in this special situation is in contrast to FF and friends. I used asXml() in the test case only, to quickly show the effect. Checking for the existence of entities in the XML was the simplest way to make the test case fail. If that encoding would not happen, we would not see entities in the XML.
Hi Joerg,
did a first attempt to fix this. Hope my understanding of the problem is correct.
Please try if the build is working again and report back.
Hi Ronald,
just a short update: I tried one of yesterday's snapshot builds, but the issue is still present. On the other hand, I am not sure if your modifications really made it into that build. The build server appears to have some problems right now, so I will wait for another successful build and retry.
Best,
J.
Hi Ronald,
rechecked with the latest build from this morning. The issue is gone.
Thanks!
J.