Menu

#34 CDATA blocks should be stripped in scripts/style elements

v 2.4
closed-fixed
nobody
None
5
2013-05-18
2009-04-14
Anonymous
No

When useCdata is true then any existing CDATA block should be removed as otherwise this leads to 2 nested CDATA sections which is not valid and fails with XML parsers.

Discussion

  • Vincent Massol

    Vincent Massol - 2009-04-14

    In addition note that for the following example there are 3 ContentToken generated (and not one) which means that all htmlcleaner serializers fail to generate valid content:

    "<script type=\"text/javascript\">\n"
    + "// <![CDATA[\n"
    + "function escapeForXML(origtext) {\n"
    + " return origtext.replace(/\\&/g,'&'+'amp;').replace(/</g,'&'+'lt;')\n"
    + " .replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');"
    + "}\n"
    + "// ]]>\n"
    + "</script>");

    The problem is that code such as this one is not correct since there are several ContentToken generated:

    else if (item instanceof ContentToken) {
    String nodeName = element.getNodeName();
    ContentToken contentToken = (ContentToken) item;
    String content = contentToken.getContent();
    boolean specialCase = props.isUseCdataForScriptAndStyle() &&
    ("script".equalsIgnoreCase(nodeName) || "style".equalsIgnoreCase(nodeName));
    if (escapeXml && !specialCase) {
    content = Utils.escapeXml(content, props, true);
    }
    element.appendChild( specialCase ? document.createCDATASection(content) : document.createTextNode(content) );

    Namely the CDATA section in the example is split into several ContentToken

     
  • Vladimir Nikic

    Vladimir Nikic - 2010-12-05

    In HtmlCleaner added html'based serialiyers which leave script and stzle blocks as original, and in xml serialiyation inner CTADA blocka are escaped to make well'formed XML

     
  • Vladimir Nikic

    Vladimir Nikic - 2010-12-05
    • status: open --> closed-fixed
     
  • Vincent Massol

    Vincent Massol - 2010-12-06
    • status: closed-fixed --> open-fixed
     
  • Vincent Massol

    Vincent Massol - 2010-12-06

    Thanks a lot for reviewing and fixing issues Vladimir. At xwiki (xwiki.org) we were worried that this project was dead and we were considering switching to something else so it's really nice to see if isn't the case!

    Any idea when 2.2 will be out?

     
  • Scott Wilson

    Scott Wilson - 2013-05-18
    • status: open-fixed --> closed-fixed
    • Group: --> v 2.4
     

Log in to post a comment.

MongoDB Logo MongoDB