Skip to content

Commit

Permalink
TOOL-739 backspace char (#95)
Browse files Browse the repository at this point in the history
* TOOL-739 added illegal character filter

* TOOL-739 comment fixture

* added unit test
  • Loading branch information
trapacska authored Jul 12, 2019
1 parent 5cff40d commit b6f01c2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/converters/xcresult/xcresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package xcresult

import (
"path/filepath"
"strings"
"unicode"

"github.com/bitrise-io/go-utils/fileutil"
"github.com/bitrise-io/go-utils/pathutil"
Expand Down Expand Up @@ -32,13 +34,42 @@ func (h *Converter) Detect(files []string) bool {
return false
}

// by one of our issue reports, need to replace backspace char (U+0008) as it is an invalid character for xml unmarshaller
// the legal character ranges are here: https://www.w3.org/TR/REC-xml/#charsets
// so the exclusion will be:
/*
\u0000 - \u0008
\u000B
\u000C
\u000E - \u001F
\u007F - \u0084
\u0086 - \u009F
\uD800 - \uDFFF
Unicode range D800–DFFF is used as surrogate pair. Unicode and ISO/IEC 10646 do not assign characters to any of the code points in the D800–DFFF range, so an individual code value from a surrogate pair does not represent a character. (A couple of code points — the first from the high surrogate area (D800–DBFF), and the second from the low surrogate area (DC00–DFFF) — are used in UTF-16 to represent a character in supplementary planes)
\uFDD0 - \uFDEF; \uFFFE; \uFFFF
*/
// These are non-characters in the standard, not assigned to anything; and have no meaning.
func filterIllegalChars(data []byte) (filtered []byte) {
illegalCharFilter := func(r rune) rune {
if unicode.IsPrint(r) {
return r
}
return -1
}
filtered = []byte(strings.Map(illegalCharFilter, string(data)))
return
}

// XML ...
func (h *Converter) XML() (junit.XML, error) {
data, err := fileutil.ReadBytesFromFile(h.testSummariesPlistPath)
if err != nil {
return junit.XML{}, err
}

data = filterIllegalChars(data)

var plistData TestSummaryPlist
if _, err := plist.Unmarshal(data, &plistData); err != nil {
return junit.XML{}, err
Expand Down
15 changes: 15 additions & 0 deletions test/converters/xcresult/xcresult_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package xcresult

import (
"reflect"
"testing"
)

func Test_filterIllegalChars(t *testing.T) {
// \b == /u0008 -> backspace
content := []byte("test\b text")

if !reflect.DeepEqual(filterIllegalChars(content), []byte("test text")) {
t.Fatal("illegal character is not removed")
}
}

0 comments on commit b6f01c2

Please sign in to comment.