Skip to content

Commit

Permalink
Fix for issue nHapiNET#51 on nHapi duaneedwards github repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
gap777 committed May 11, 2016
1 parent 0014942 commit a25e4f3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions NHapi20/NHapi.Base/Parser/PipeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ protected internal override IMessage DoParse(String message, String version)

FilterIterator segmentIter = new FilterIterator(messageIter, new SegmentOnlyPredicate());

string lastSegmentName = null;
string lastSegmentName = "MSH";
String[] segments = Split(message, segDelim);
IStructure lastStructureParsed = theMessage;
EncodingCharacters encodingChars = GetEncodingChars(message);
for (int i = 0; i < segments.Length; i++)
{
Expand All @@ -236,9 +237,7 @@ protected internal override IMessage DoParse(String message, String version)
log.Debug("Parsing segment " + name);
if (!name.Equals(lastSegmentName, StringComparison.CurrentCultureIgnoreCase))
{
// If the message iterator passes a segment that is later encountered the message object won't be properly parsed.
// Rebuild the iterator for each segment, or fix iterator logic in handling unexpected segments.
messageIter = new MessageIterator(theMessage, "MSH", true);
messageIter = new MessageIterator(lastStructureParsed, name, true);
segmentIter = new FilterIterator(messageIter, new SegmentOnlyPredicate());
lastSegmentName = name;
}
Expand All @@ -248,7 +247,9 @@ protected internal override IMessage DoParse(String message, String version)
FilterIterator dirIter = new FilterIterator(segmentIter, new StructureNamePredicate(name));
if (dirIter.MoveNext())
{
Parse((ISegment) dirIter.Current, segments[i], encodingChars);
ISegment targetSegment = (ISegment) dirIter.Current;
Parse(targetSegment, segments[i], encodingChars);
lastStructureParsed = targetSegment;
}
}
}
Expand Down

0 comments on commit a25e4f3

Please sign in to comment.