Browse Source

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 <tsmock@fb.com>

This closes #175 pull request at github.com/apache/ant
master
Taylor Smock Jaikiran Pai 3 years ago
parent
commit
aa47924dc2
4 changed files with 20 additions and 2 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +12
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java

+ 1
- 0
CONTRIBUTORS View File

@@ -423,6 +423,7 @@ Takashi Okamoto
TAMURA Kent
Taoufik Romdhane
Tariq Master
Taylor Smock
Thomas Aglassinger
Thomas Butz
Thomas Christen


+ 3
- 0
WHATSNEW View File

@@ -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:
--------------



+ 4
- 0
contributors.xml View File

@@ -1744,6 +1744,10 @@
<first>Tariq</first>
<last>Master</last>
</name>
<name>
<first>Taylor</first>
<last>Smock</last>
</name>
<name>
<first>Thomas</first>
<last>Aglassinger</last>


+ 12
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java View File

@@ -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;


Loading…
Cancel
Save