Skip to content

Commit 827728d

Browse files
committed
Parse message with no body fields
Previously, the bodyBytes was ending up with the trailer in it when the body contained no fields, and trailerBytes was empty
1 parent 8be2911 commit 827728d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

message.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ func ParseMessageWithDataDictionary(
210210

211211
trailerBytes := []byte{}
212212
foundBody := false
213+
foundTrailer := false
213214
for {
214215
parsedFieldBytes = &msg.fields[fieldIndex]
215216
if xmlDataLen > 0 {
@@ -228,6 +229,7 @@ func ParseMessageWithDataDictionary(
228229
msg.Header.add(msg.fields[fieldIndex : fieldIndex+1])
229230
case isTrailerField(parsedFieldBytes.tag, transportDataDictionary):
230231
msg.Trailer.add(msg.fields[fieldIndex : fieldIndex+1])
232+
foundTrailer = true
231233
default:
232234
foundBody = true
233235
trailerBytes = rawBytes
@@ -247,6 +249,12 @@ func ParseMessageWithDataDictionary(
247249
fieldIndex++
248250
}
249251

252+
// This will happen if there are no fields in the body
253+
if foundTrailer && !foundBody {
254+
trailerBytes = rawBytes
255+
msg.bodyBytes = nil
256+
}
257+
250258
// Body length would only be larger than trailer if fields out of order.
251259
if len(msg.bodyBytes) > len(trailerBytes) {
252260
msg.bodyBytes = msg.bodyBytes[:len(msg.bodyBytes)-len(trailerBytes)]

0 commit comments

Comments
 (0)