File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -236,5 +236,27 @@ func formatDuration(d time.Duration) string {
236
236
237
237
// formatOutput combines the lines from the given output into a single string.
238
238
func formatOutput (output []string ) string {
239
- return strings .Join (output , "\n " )
239
+ return escapeIllegalChars (strings .Join (output , "\n " ))
240
+ }
241
+
242
+ func escapeIllegalChars (str string ) string {
243
+ return strings .Map (func (r rune ) rune {
244
+ if isInCharacterRange (r ) {
245
+ return r
246
+ }
247
+ return '�'
248
+ }, str )
249
+ }
250
+
251
+ // Decide whether the given rune is in the XML Character Range, per
252
+ // the Char production of https://www.xml.com/axml/testaxml.htm,
253
+ // Section 2.2 Characters.
254
+ // Form: encoding/xml/xml.go
255
+ func isInCharacterRange (r rune ) (inrange bool ) {
256
+ return r == 0x09 ||
257
+ r == 0x0A ||
258
+ r == 0x0D ||
259
+ r >= 0x20 && r <= 0xD7FF ||
260
+ r >= 0xE000 && r <= 0xFFFD ||
261
+ r >= 0x10000 && r <= 0x10FFFF
240
262
}
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