Author: carnold
Date: Wed Aug 22 16:55:09 2007
New Revision: 568775
URL: http://svn.apache.org/viewvc?rev=568775&view=rev
Log:
Bug 37560: XMLLayout does not escape CDATA sections in NDC or throwables
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/xml/XSLTLayoutTest.java
Modified:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/xml/XSLTLayoutTest.java
URL:
http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/xml/XSLTLayoutTest.java?rev=568775&r1=568774&r2=568775&view=diff
==============================================================================
---
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/xml/XSLTLayoutTest.java
(original)
+++
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/xml/XSLTLayoutTest.java
Wed Aug 22 16:55:09 2007
@@ -37,6 +37,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
@@ -379,6 +380,58 @@
assertTrue(Compare.compare(XSLTLayoutTest.class,
"filtered", "witness/xml/xsltLayout.4"));
}
+
+ /**
+ * Tests CDATA element within NDC content. See bug 37560.
+ */
+ public void testNDCWithCDATA() throws Exception {
+ Logger logger = Logger.getLogger("com.example.bar");
+ Level level = Level.INFO;
+ String ndcMessage ="<envelope><faultstring><![CDATA[The
EffectiveDate]]></faultstring><envelope>";
+ NDC.push(ndcMessage);
+ LoggingEvent event =
+ new LoggingEvent(
+ "com.example.bar", logger, level, "Hello, World", null);
+ Layout layout = createLayout();
+ String result = layout.format(event);
+ NDC.clear();
+ Element parsedResult = parse(result);
+ NodeList ndcs = parsedResult.getElementsByTagName("log4j:NDC");
+ assertEquals(1, ndcs.getLength());
+ StringBuffer buf = new StringBuffer();
+ for(Node child = ndcs.item(0).getFirstChild();
+ child != null;
+ child = child.getNextSibling()) {
+ buf.append(child.getNodeValue());
+ }
+ assertEquals(ndcMessage, buf.toString());
+
+ }
+
+ /**
+ * Tests CDATA element within exception. See bug 37560.
+ */
+ public void testExceptionWithCDATA() throws Exception {
+ Logger logger = Logger.getLogger("com.example.bar");
+ Level level = Level.INFO;
+ String exceptionMessage ="<envelope><faultstring><![CDATA[The
EffectiveDate]]></faultstring><envelope>";
+ LoggingEvent event =
+ new LoggingEvent(
+ "com.example.bar", logger, level, "Hello, World", new
Exception(exceptionMessage));
+ Layout layout = createLayout();
+ String result = layout.format(event);
+ Element parsedResult = parse(result);
+ NodeList throwables =
parsedResult.getElementsByTagName("log4j:throwable");
+ assertEquals(1, throwables.getLength());
+ StringBuffer buf = new StringBuffer();
+ for(Node child = throwables.item(0).getFirstChild();
+ child != null;
+ child = child.getNextSibling()) {
+ buf.append(child.getNodeValue());
+ }
+ assertTrue(buf.toString().indexOf(exceptionMessage) != -1);
+ }
+
private static void clearMDC() {
Hashtable context = MDC.getContext();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]