From 203458fdf76bd033da1733f12663f3520cd2a0e8 Mon Sep 17 00:00:00 2001 From: Nathan McRae Date: Sat, 9 Mar 2024 09:57:56 -0800 Subject: [PATCH] Fix some end-of-file simple TSV parsing --- SaneTsv.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/SaneTsv.cs b/SaneTsv.cs index 25ef493..9cacc17 100644 --- a/SaneTsv.cs +++ b/SaneTsv.cs @@ -1033,13 +1033,20 @@ public class SaneTsv fields.Add(fieldBytes.ToArray()); - if (fields.Count == 0) + if (fields.Count == 0 && endIndex == inputBuffer.Length) { throw new Exception("Found 0 fields on last line. Possibly because of extra \\n after last record"); } if (numFields != fields.Count) { - throw new Exception($"Expected {numFields} fields on line {line}, but found {fields.Count}"); + if (endIndex == inputBuffer.Length) + { + throw new Exception($"Expected {numFields} fields on line {line}, but found {fields.Count}"); + } + else + { + return records.ToArray(); + } } else {