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

XmlNodePrinter does not propertly handle special characters within tag values

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.6, 1.6-beta-1
    • Fix Version/s: 1.5.7, 1.6-beta-2
    • Component/s: XML Processing
    • Labels:
      None
    • Flags:
      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. patch.txt
          0.4 kB
          Raptor Audio
        2. XmlTester.groovy
          0.3 kB
          Raptor Audio

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: