From ea09ce079ead39657c00b40b68bc1fa3a31b87d4 Mon Sep 17 00:00:00 2001 From: William Hesketh Date: Tue, 19 Dec 2017 15:27:18 +0000 Subject: [PATCH] Fixed bug with ragged right files If the length of a line in a file falls short of providing a value for each field (ragged right file), the linePosition can end up equal to the length of the line. This doesn't cause a problem if this is the last field, but does pose a problem if there are additional fields to be checked. On getting the value for the next field the linePosition ends up after the end of the line and throws an exception. The change makes sure that the linePosition is either at or below the end of the line length before trying to start the Substring function. This forces either the NullValue to be returned, or the exception defined a few lines below to be thrown. --- .../Implementation/FixedLengthLineParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FlatFile.FixedLength/Implementation/FixedLengthLineParser.cs b/src/FlatFile.FixedLength/Implementation/FixedLengthLineParser.cs index bb45fc3..ce09de0 100644 --- a/src/FlatFile.FixedLength/Implementation/FixedLengthLineParser.cs +++ b/src/FlatFile.FixedLength/Implementation/FixedLengthLineParser.cs @@ -31,7 +31,7 @@ private static string GetValueFromLine(string line, int linePosition, IFixedFiel { if (linePosition + field.Length > line.Length) { - if ((linePosition + field.Length) - line.Length != field.Length) + if ((linePosition + field.Length) - line.Length != field.Length && linePosition <= line.Length) { return line.Substring(linePosition); }