Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-71139] Alternate reproducer for NUL issue in SuiteResult.stdout #520

Merged
merged 1 commit into from Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/hudson/tasks/junit/TestResultAction.java
Expand Up @@ -326,7 +326,7 @@ public Object readResolve() {

private static final Logger logger = Logger.getLogger(TestResultAction.class.getName());

private static final XStream XSTREAM = new XStream2();
static final XStream XSTREAM = new XStream2();

static {
XSTREAM.alias("result",TestResult.class);
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/hudson/tasks/junit/SuiteResultTest.java
Expand Up @@ -27,10 +27,13 @@
import java.io.File;
import java.util.List;
import java.net.URISyntaxException;
import org.apache.commons.io.FileUtils;

import hudson.XmlFile;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.Issue;

import java.io.FileWriter;
Expand All @@ -51,6 +54,9 @@
*/
public class SuiteResultTest {

@Rule
public TemporaryFolder tmp = new TemporaryFolder();

private File getDataFile(String name) throws URISyntaxException {
return new File(SuiteResultTest.class.getResource(name).toURI());
}
Expand Down Expand Up @@ -295,6 +301,19 @@ public void testSuiteStdioTrimmingSurefireOnFail() throws Exception {
}
}

@Issue("JENKINS-71139")
@Test
public void stdioNull() throws Exception {
SuiteResult sr = parseOne(getDataFile("TEST-null.xml"));
XmlFile f = new XmlFile(TestResultAction.XSTREAM, tmp.newFile("junitResult.xml"));
f.write(sr);
FileUtils.copyFile(f.getFile(), System.out);
System.out.println();
sr = (SuiteResult) f.read();
System.out.println(TestResultAction.XSTREAM.toXML(sr));
assertEquals("foo\u0000bar", sr.getStdout());
}

/**
* When the testcase fails to initialize (exception in constructor or @Before)
* there is no 'testcase' element at all.
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/hudson/tasks/junit/TEST-null.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite errors="1" failures="0" name="x" tests="1">
<testcase classname="X" name="x">
<error message="x">xxx</error>
</testcase>
<!--
<system-out><![CDATA[foo&amp#0;bar]]></system-out>
<system-out><![CDATA[foo&#x0;bar]]></system-out>
<system-err><![CDATA[]]></system-err>
-->
</testsuite>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ od -a src/test/resources/hudson/tasks/junit/null-output.txt
0000000   f   o   o nul   b   a   r
0000007

Binary file not shown.