Uploaded image for project: 'Shale'
  1. Shale
  2. SHALE-488

Script contents should be enclosed in CDATA section for XML documents

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.0.4
    • None
    • Validator
    • None
    • XML content types, including XHTML

    Description

      When the validator script gets rendered, it outputs raw Javascript inside the <script>
      tags. The Javascript includes characters like & which need to be escaped
      or in a CDATA section in XML. For XUL or XHTML, this is a problem. I
      guess that XHTML parsers are more lenient about this so that's why the
      problem never showed up? Anyway the fix, which was also suggested by
      Gary VanMatre, was to enclose the script contents in an XML CDATA
      section. So in
      src/main/java/org/apache/shale/validator/faces/ValidatorScript.java I have:

      private void writeScriptStart(ResponseWriter writer) throws IOException {
      writer.startElement("script", this);
      writer.writeAttribute("type", "text/javascript", null);
      writer.writeAttribute("language", "Javascript1.1", null);
      writer.write("\n");

      // jtsay added
      // Enclose XML in CDATA so special characters can be used without
      escaping.
      if (!"text/html".equals(writer.getContentType()))

      { writer.write("<![CDATA[\n"); }

      }

      and

      private void writeScriptEnd(ResponseWriter writer) throws IOException {
      // jtsay added
      if (!"text/html".equals(writer.getContentType()))

      { writer.write("\n]]>\n"); }

      writer.write("\n");
      writer.endElement("script");
      }

      This assumes if we are not rendering text/html, we must be rendering
      some sort of XML. Sound reasonable?

      Attachments

        Activity

          People

            Unassigned Unassigned
            jctsay Jeff Tsay
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: