Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
1.6.4, 1.7.4
-
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.