@@ -310,6 +310,7 @@ func parseGroup(mp *msgParser, tags []Tag) {
310310 dm := mp .msg .fields [mp .fieldIndex : mp .fieldIndex + 1 ]
311311 fields := getGroupFields (mp .msg , tags , mp .appDataDictionary )
312312
313+ parseLoop:
313314 for {
314315 mp .fieldIndex ++
315316 mp .parsedFieldBytes = & mp .msg .fields [mp .fieldIndex ]
@@ -350,16 +351,18 @@ func parseGroup(mp *msgParser, tags []Tag) {
350351 fields = getGroupFields (mp .msg , searchTags , mp .appDataDictionary )
351352 continue
352353 }
353- if len (tags ) > 1 {
354- searchTags = tags [:len (tags )- 1 ]
355- }
356- // Did this tag occur after a nested group and belongs to the parent group.
357- if isNumInGroupField (mp .msg , searchTags , mp .appDataDictionary ) {
358- // Add the field member to the group.
359- dm = append (dm , * mp .parsedFieldBytes )
360- // Continue parsing the parent group.
361- fields = getGroupFields (mp .msg , searchTags , mp .appDataDictionary )
362- continue
354+ // The field closed one or more nested groups. Pop back up the
355+ // group stack: if some ancestor's template owns this tag, resume
356+ // parsing in that scope. Otherwise the field belongs at the body
357+ // level and must surface there — not be absorbed into the parent.
358+ for len (tags ) > 1 {
359+ tags = tags [:len (tags )- 1 ]
360+ ancestorFields := getGroupFields (mp .msg , tags , mp .appDataDictionary )
361+ if isGroupMember (mp .parsedFieldBytes .tag , ancestorFields ) {
362+ dm = append (dm , * mp .parsedFieldBytes )
363+ fields = ancestorFields
364+ continue parseLoop
365+ }
363366 }
364367 // Add the repeating group.
365368 mp .msg .Body .add (dm )
0 commit comments