Skip to content

Commit e38dbd1

Browse files
authored
[JENKINS-71139] Do not even try to save NULs (#521)
1 parent fe62d9e commit e38dbd1

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/main/java/hudson/tasks/junit/CaseResult.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ public CaseResult(
148148
this.errorStackTrace = stacktrace;
149149
this.errorDetails = errorDetails;
150150
this.parent = parent;
151-
this.stdout = stdout;
152-
this.stderr = stderr;
151+
this.stdout = fixNULs(stdout);
152+
this.stderr = fixNULs(stderr);
153153
this.duration = duration;
154154

155155
this.skipped = skippedMessage != null;
@@ -189,8 +189,8 @@ public CaseResult(
189189
skippedMessage = getSkippedMessage(testCase);
190190
@SuppressWarnings("LeakingThisInConstructor")
191191
Collection<CaseResult> _this = Collections.singleton(this);
192-
stdout = possiblyTrimStdio(_this, keepLongStdio, testCase.elementText("system-out"));
193-
stderr = possiblyTrimStdio(_this, keepLongStdio, testCase.elementText("system-err"));
192+
stdout = fixNULs(possiblyTrimStdio(_this, keepLongStdio, testCase.elementText("system-out")));
193+
stderr = fixNULs(possiblyTrimStdio(_this, keepLongStdio, testCase.elementText("system-err")));
194194
}
195195

196196
static String possiblyTrimStdio(Collection<CaseResult> results, boolean keepLongStdio, String stdio) { // HUDSON-6516
@@ -209,6 +209,10 @@ static String possiblyTrimStdio(Collection<CaseResult> results, boolean keepLong
209209
return stdio.subSequence(0, halfMaxSize) + "\n...[truncated " + middle + " chars]...\n" + stdio.subSequence(len - halfMaxSize, len);
210210
}
211211

212+
static String fixNULs(String stdio) { // JENKINS-71139
213+
return stdio == null ? null : stdio.replace("\u0000", "^@");
214+
}
215+
212216
/**
213217
* Flavor of {@link #possiblyTrimStdio(Collection, boolean, String)} that doesn't try to read the whole thing into memory.
214218
*/

src/main/java/hudson/tasks/junit/SuiteResult.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public final class SuiteResult implements Serializable {
114114
*/
115115
public SuiteResult(String name, String stdout, String stderr, @CheckForNull PipelineTestDetails pipelineTestDetails) {
116116
this.name = name;
117-
this.stderr = stderr;
118-
this.stdout = stdout;
117+
this.stderr = CaseResult.fixNULs(stderr);
118+
this.stdout = CaseResult.fixNULs(stdout);
119119
// runId is generally going to be not null, but we only care about it if both it and nodeId are not null.
120120
if (pipelineTestDetails != null && pipelineTestDetails.getNodeId() != null) {
121121
this.nodeId = pipelineTestDetails.getNodeId();
@@ -283,8 +283,8 @@ private SuiteResult(File xmlReport, Element suite, boolean keepLongStdio, @Check
283283
}
284284
}
285285

286-
this.stdout = stdout;
287-
this.stderr = stderr;
286+
this.stdout = CaseResult.fixNULs(stdout);
287+
this.stderr = CaseResult.fixNULs(stderr);
288288
}
289289

290290
public void addCase(CaseResult cr) {

src/test/java/hudson/tasks/junit/SuiteResultTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public void stdioNull() throws Exception {
311311
System.out.println();
312312
sr = (SuiteResult) f.read();
313313
System.out.println(TestResultAction.XSTREAM.toXML(sr));
314-
assertEquals("foo\u0000bar", sr.getStdout());
314+
assertEquals("foo^@bar", sr.getStdout());
315315
}
316316

317317
/**

0 commit comments

Comments
 (0)