Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3002

XmlNodePrinter does not propertly handle special characters within tag values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.6, 1.6-beta-1
    • 1.5.7, 1.6-beta-2
    • XML Processing
    • None
    • Patch

    Description

      A previous fix for the XmlNodePrinter escaped special characters within attributes, but not within the value. The printEscaped method should also be called within the value.

      import groovy.util.XmlNodePrinter;
      
      def doc = """<Root attribute="&lt;&quot;&amp;&gt;">&lt;&amp;&gt;</Root>""";
      
      def root = new XmlParser().parseText(doc);
      def writer = new StringWriter();
      
      new XmlNodePrinter(new PrintWriter(writer)).print(root);
      
      println writer.toString();
      

      Originally would produce:

      <Root attribute="&lt;&quot;&amp;&gt;">
        <&>
      </Root>
      

      After patch, produces:

      
      

      Attachments

        1. XmlTester.groovy
          0.3 kB
          Raptor Audio
        2. patch.txt
          0.4 kB
          Raptor Audio

        Activity

          People

            paulk Paul King
            raptoraudio Raptor Audio
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: