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

Round-tripping XML which contains a newline character reference in an attribute's value removes the character reference

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.6.4, 1.7.4
    • 1.7.5, 1.8-beta-2
    • XML Processing
    • None
    • Patch

    Description

      Given an XML file which contains a newline character reference ( ) in the value of an attribute, the following groovy code incorrectly outputs the actual newline character instead of the original character reference. This is a significant problem because the XML standard dictates that newlines found in the value of an attribute must be treated as a space. Thus, if any XML parser reads the output of this groovy snippet, it is as if the newline is gone.

      newline.xml:
      <option name="LINE_SEPARATOR" value=" "/>

      groovy:

      def fileWriter = new FileWriter('./newline-roundtrip.xml')
      def input = new XmlParser().parse('./newline.xml')
      PrintWriter printWriter = new PrintWriter(fileWriter)
      new XmlNodePrinter(printWriter).print(input)
      printWriter.flush()

      I've attached a junit test which demonstrates the problem.

      Attachments

        1. GROOVY-4380-1_7_x.diff
          3 kB
          Ben Jansen
        2. NewlineEntityFailure.groovy
          0.7 kB
          Ben Jansen

        Activity

          People

            paulk Paul King
            aogail Ben Jansen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: