From 8735854937ed742505e46f5a8591f9060e6fc931 Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 8 Dec 2025 10:57:49 +0900 Subject: [PATCH] Improve handling of doubled-up qualifiers in CSV parsing Handle cases where line ends with a qualifier and not at stream end. --- src/CSVStateMachine.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/CSVStateMachine.cs b/src/CSVStateMachine.cs index f92d083..7077bfe 100644 --- a/src/CSVStateMachine.cs +++ b/src/CSVStateMachine.cs @@ -180,6 +180,18 @@ public string[] ParseChunk(string chunk, bool reachedEnd) return null; } + //If the line ends with a qualifier and we're not at the end of the stream, + //it may be first qualifier from a doubled-up qualifier, so we should read the next chunk. + if (p2 == _line.Length - 1) + { + if (!reachedEnd) + { + // Backtrack one character so we can move forward when the next chunk loads + _position--; + return null; + } + } + // Append the text between the qualifiers _work.Append(_line.Substring(_position + 1, p2 - _position - 1)); _position = p2; @@ -273,4 +285,4 @@ public string[] ParseChunk(string chunk, bool reachedEnd) return null; } } -} \ No newline at end of file +}