Transformer creates duplicate CarriageReturn in CDATA section on windows
------------------------------------------------------------------------
Key: XALANJ-2547
URL: https://issues.apache.org/jira/browse/XALANJ-2547
Project: XalanJ2
Issue Type: Bug
Security Level: No security risk; visible to anyone (Ordinary problems in
Xalan projects. Anybody can view the issue.)
Components: transformation
Affects Versions: 2.7.1
Environment: Windows 7 64
Reporter: Daniel Schwering
Priority: Minor
When I have a Windows Line Break (CR+LF) in a CDATA section, the transformer
turns it into (CR+CR+LF), which most editors display as an extra blank line.
Test code:
import static org.junit.Assert.assertEquals;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.junit.Test;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class XmlCdataWithCrTest {
private static final String LINE_SEPARATOR =
System.getProperty("line.separator");
@Test
public void testXmlCdataWithCr() throws TransformerException,
ParserConfigurationException {
Document doc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element root = doc.createElement("root");
doc.appendChild(root);
CDATASection cdataSection = doc.createCDATASection("a" + LINE_SEPARATOR
+ "b");
root.appendChild(cdataSection);
StringWriter writer = new StringWriter();
Transformer transformer =
TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(new DOMSource(doc), new StreamResult(writer));
String result = writer.toString();// .replace("\r\r", "\r");
String expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><![CDATA[a" +
LINE_SEPARATOR + "b]]></root>"
+ LINE_SEPARATOR;
assertEquals(expected, result);
}
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]