From 827728d16fa842d610e0095d57f3836eac6906bd Mon Sep 17 00:00:00 2001 From: Mike Gatny Date: Mon, 15 Apr 2024 18:34:07 -0400 Subject: [PATCH] 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 --- message.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/message.go b/message.go index ec550f2ef..566b48eb7 100644 --- a/message.go +++ b/message.go @@ -210,6 +210,7 @@ func ParseMessageWithDataDictionary( trailerBytes := []byte{} foundBody := false + foundTrailer := false for { parsedFieldBytes = &msg.fields[fieldIndex] if xmlDataLen > 0 { @@ -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 @@ -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)]