xalan-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ian Beaumont (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (XALANJ-2547) Transformer creates duplicate CarriageReturn in CDATA section on windows
Date Wed, 08 Jan 2014 12:51:50 GMT

    [ https://issues.apache.org/jira/browse/XALANJ-2547?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13865379#comment-13865379
] 

Ian Beaumont commented on XALANJ-2547:
--------------------------------------

My understanding is that the CDATA data should not be changed.  According to this
http://www.w3.org/TR/REC-xml/#sec-line-ends
only "parsed entities" should have the line breaks changed and don't CDATA sections contain
"unparsed character data"?


> 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
>              Labels: newbie
>
> 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 was sent by Atlassian JIRA
(v6.1.5#6160)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xalan.apache.org
For additional commands, e-mail: dev-help@xalan.apache.org


Mime
View raw message