File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 3
3
package junit
4
4
5
5
import (
6
+ "bytes"
6
7
"encoding/xml"
7
8
"fmt"
8
9
"strings"
@@ -235,6 +236,16 @@ func formatDuration(d time.Duration) string {
235
236
}
236
237
237
238
// formatOutput combines the lines from the given output into a single string.
238
- func formatOutput (output []string , indent int ) string {
239
- return strings .Join (output , "\n " )
239
+ func formatOutput (output []string , _ int ) string {
240
+ buf := bytes .NewBufferString ("" )
241
+ for i , o := range output {
242
+ err := xml .EscapeText (buf , []byte (o ))
243
+ if err != nil {
244
+ return "formatOutput: " + err .Error ()
245
+ }
246
+ if i < len (output )- 1 {
247
+ buf .WriteString ("\n " )
248
+ }
249
+ }
250
+ return buf .String ()
240
251
}
Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ func TestCreateFromReport(t *testing.T) {
26
26
Result : gtr .Pass ,
27
27
Output : []string {"ok" },
28
28
},
29
+ {
30
+ Name : "TestEscapeOutput" ,
31
+ Result : gtr .Pass ,
32
+ Output : []string {"\x00 \v \f \t \\ " },
33
+ },
29
34
{
30
35
Name : "TestFail" ,
31
36
Result : gtr .Fail ,
@@ -47,14 +52,14 @@ func TestCreateFromReport(t *testing.T) {
47
52
}
48
53
49
54
want := Testsuites {
50
- Tests : 6 ,
55
+ Tests : 7 ,
51
56
Errors : 3 ,
52
57
Failures : 1 ,
53
58
Skipped : 1 ,
54
59
Suites : []Testsuite {
55
60
{
56
61
Name : "package/name" ,
57
- Tests : 6 ,
62
+ Tests : 7 ,
58
63
Errors : 3 ,
59
64
ID : 0 ,
60
65
Failures : 1 ,
@@ -72,6 +77,12 @@ func TestCreateFromReport(t *testing.T) {
72
77
Time : "0.000" ,
73
78
SystemOut : & Output {Data : "ok" },
74
79
},
80
+ {
81
+ Name : "TestEscapeOutput" ,
82
+ Classname : "package/name" ,
83
+ Time : "0.000" ,
84
+ SystemOut : & Output {Data : `��� 	\` },
85
+ },
75
86
{
76
87
Name : "TestFail" ,
77
88
Classname : "package/name" ,
You can’t perform that action at this time.
0 commit comments