Skip to content

Commit

Permalink
Merge pull request #168 from negbie/master
Browse files Browse the repository at this point in the history
Check again every HEP Type for valid UTF8
  • Loading branch information
negbie committed Dec 22, 2018
2 parents db7f267 + 49fa078 commit 8795d64
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,20 @@ func (h *HEP) normPayload() {
logp.Warn("%v", err)
}
}
if h.ProtoType == 1 {
if !utf8.ValidString(h.Payload) {
v := make([]rune, 0, len(h.Payload))
for i, r := range h.Payload {
if r == utf8.RuneError {
_, size := utf8.DecodeRuneInString(h.Payload[i:])
if size == 1 {
continue
}
} else if r == '\x00' {
if !utf8.ValidString(h.Payload) {
v := make([]rune, 0, len(h.Payload))
for i, r := range h.Payload {
if r == utf8.RuneError {
_, size := utf8.DecodeRuneInString(h.Payload[i:])
if size == 1 {
continue
}
v = append(v, r)
} else if r == '\x00' {
continue
}
h.Payload = string(v)
v = append(v, r)
}
h.Payload = string(v)
}
}

Expand Down

0 comments on commit 8795d64

Please sign in to comment.