Skip to content

Commit

Permalink
Add more thorough escape sequence remover
Browse files Browse the repository at this point in the history
  • Loading branch information
laurikoobas committed Nov 16, 2018
1 parent ade5987 commit 896e46f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bread/basetype_readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ func Duration(ob *bytes.Buffer, b []byte, offset int32, _ int32) int32 {
return size
}

func stripCtlAndExtFromBytes(b []byte) []byte {
var bl int
for i := 0; i < len(b); i++ {
c := b[i]
if c >= 32 && c < 127 {
b[bl] = c
bl++
}
}
return b[:bl]
}

// String reads ...
func String(ob *bytes.Buffer, b []byte, offset int32, _ int32) int32 {
var (
Expand All @@ -156,7 +168,7 @@ func String(ob *bytes.Buffer, b []byte, offset int32, _ int32) int32 {
stringLength = *(*uint32)(unsafe.Pointer(&b[offset+size]))
size = size + 4
// log.Debugf("String length: %v", stringLength)
stringValue := string(bytes.Replace(b[offset+size:offset+size+int32(stringLength)], []byte("\xff"), []byte(""), -1))
stringValue := string(stripCtlAndExtFromBytes(b[offset+size : offset+size+int32(stringLength)]))
// ob.WriteByte('"')
ob.WriteString(strconv.Quote(stringValue))
// ob.WriteByte('"')
Expand Down

0 comments on commit 896e46f

Please sign in to comment.