This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/master by this push:
     new aa47924  Fix an issue in LegacyXmlResultFormatter with ]]> in 
stacktraces
aa47924 is described below

commit aa47924dc2aaac617bfa19731bcbfe6745711eef
Author: Taylor Smock <tsm...@fb.com>
AuthorDate: Fri Jan 21 08:52:25 2022 -0700

    Fix an issue in LegacyXmlResultFormatter with ]]> in stacktraces
    
    Bugzilla Report 65833
    
    This occurs when the stacktrace message contains ]]>, which is the CDATA
    end code. There is no escape, so it must be replaced with `]]` + `]]>` +
    `<![CDATA[` + `>`, which means that the CDATA section is split.
    
    Signed-off-by: Taylor Smock <tsm...@fb.com>
    
    This closes #175 pull request at github.com/apache/ant
---
 CONTRIBUTORS                                               |  1 +
 WHATSNEW                                                   |  3 +++
 contributors.xml                                           |  4 ++++
 .../optional/junitlauncher/LegacyXmlResultFormatter.java   | 14 ++++++++++++--
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index b174309..e721b2f 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -423,6 +423,7 @@ Takashi Okamoto
 TAMURA Kent
 Taoufik Romdhane
 Tariq Master
+Taylor Smock
 Thomas Aglassinger
 Thomas Butz
 Thomas Christen
diff --git a/WHATSNEW b/WHATSNEW
index 9ea8607..dee8ed6 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -18,6 +18,9 @@ Fixed bugs:
   PropertyHelper implementations - for example when using AntXtras.
   Bugzilla Report 65799
 
+* legacy-xml reporter of the junitlauncher task now escapes ]]> when writing 
CDATA.
+  Bugzilla Report 65833
+
 Other changes:
 --------------
 
diff --git a/contributors.xml b/contributors.xml
index 2666863..f0f5197 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -1745,6 +1745,10 @@
     <last>Master</last>
   </name>
   <name>
+    <first>Taylor</first>
+    <last>Smock</last>
+  </name>
+  <name>
     <first>Thomas</first>
     <last>Aglassinger</last>
   </name>
diff --git 
a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
 
b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
index d86c35b..3db1227 100644
--- 
a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
+++ 
b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
@@ -299,7 +299,7 @@ class LegacyXmlResultFormatter extends 
AbstractJUnitResultFormatter implements T
                 }
                 writeAttribute(writer, ATTR_TYPE, t.getClass().getName());
                 // write out the stacktrace
-                writer.writeCData(StringUtils.getStackTrace(t));
+                this.writeCDataSafely(writer, StringUtils.getStackTrace(t));
             }
             writer.writeEndElement();
         }
@@ -318,7 +318,7 @@ class LegacyXmlResultFormatter extends 
AbstractJUnitResultFormatter implements T
                 }
                 writeAttribute(writer, ATTR_TYPE, t.getClass().getName());
                 // write out the stacktrace
-                writer.writeCData(StringUtils.getStackTrace(t));
+                this.writeCDataSafely(writer, StringUtils.getStackTrace(t));
             }
             writer.writeEndElement();
         }
@@ -345,6 +345,16 @@ class LegacyXmlResultFormatter extends 
AbstractJUnitResultFormatter implements T
             writer.writeEndElement();
         }
 
+        /**
+         * Write cdata safely (escape special sequence {@code "]]>"})
+         * @param writer The xml writer to use
+         * @param cdata The cdata to write
+         * @see <a 
href="https://bz.apache.org/bugzilla/show_bug.cgi?id=65833";>Bugzilla #65833</a>
+         */
+        private void writeCDataSafely(final XMLStreamWriter writer, final 
String cdata) throws XMLStreamException {
+            writer.writeCData(cdata.replace("]]>", "]]]]><![CDATA[>"));
+        }
+
         private void writeCharactersFrom(final Reader reader, final 
XMLStreamWriter writer) throws IOException, XMLStreamException {
             final char[] chars = new char[1024];
             int numRead = -1;

Reply via email to