Menu

#1509 Script content gets HTML encoded when set as inner HTML

Latest SVN
closed
RBRi
None
1
2014-02-05
2013-06-12
No

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!

1 Attachments

Discussion

  • Joerg Werner

    Joerg Werner - 2013-06-12

    And here is a tiny test case that demonstrates this issue.

     
  • Joerg Werner

    Joerg Werner - 2013-06-12

    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).

     
  • PabloGDT

    PabloGDT - 2013-10-02

    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
  • Marc Guillemot

    Marc Guillemot - 2013-10-11

    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.

     
  • Joerg Werner

    Joerg Werner - 2013-10-23

    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.

     
  • RBRi

    RBRi - 2014-02-03
    • status: open --> pending
     
  • RBRi

    RBRi - 2014-02-03

    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.

     
  • RBRi

    RBRi - 2014-02-03
    • assigned_to: RBRi
     
  • Joerg Werner

    Joerg Werner - 2014-02-04

    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.

     
  • Joerg Werner

    Joerg Werner - 2014-02-05

    Hi Ronald,
    rechecked with the latest build from this morning. The issue is gone.

    Thanks!
    J.

     
  • Ahmed Ashour

    Ahmed Ashour - 2014-02-05
    • status: pending --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB