Skip to content

Commit

Permalink
Parse message with no body fields
Browse files Browse the repository at this point in the history
Previously, the bodyBytes was ending up with the trailer in it when the
body contained no fields, and trailerBytes was empty
  • Loading branch information
mgatny committed Apr 15, 2024
1 parent 8be2911 commit 827728d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func ParseMessageWithDataDictionary(

trailerBytes := []byte{}
foundBody := false
foundTrailer := false
for {
parsedFieldBytes = &msg.fields[fieldIndex]
if xmlDataLen > 0 {
Expand All @@ -228,6 +229,7 @@ func ParseMessageWithDataDictionary(
msg.Header.add(msg.fields[fieldIndex : fieldIndex+1])
case isTrailerField(parsedFieldBytes.tag, transportDataDictionary):
msg.Trailer.add(msg.fields[fieldIndex : fieldIndex+1])
foundTrailer = true
default:
foundBody = true
trailerBytes = rawBytes
Expand All @@ -247,6 +249,12 @@ func ParseMessageWithDataDictionary(
fieldIndex++
}

// This will happen if there are no fields in the body
if foundTrailer && !foundBody {
trailerBytes = rawBytes
msg.bodyBytes = nil
}

// Body length would only be larger than trailer if fields out of order.
if len(msg.bodyBytes) > len(trailerBytes) {
msg.bodyBytes = msg.bodyBytes[:len(msg.bodyBytes)-len(trailerBytes)]
Expand Down

0 comments on commit 827728d

Please sign in to comment.