Repository: BurntSushi/rust-csv (language: rust)

Issue:
Reader::reset doesn't reset ends
### Bug

A little hard to explain in words (might be a little late here), but here is a [Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=eb85fe146010fde6cd78bc4a6addf580) to reproduce.

`Reader::reset` doesn't seem to reset record field ends. When used on a new slice after partially processing an unterminated row, the ends are returned from the previous slice, not the new one.


Discussion / hints:
[I think `reset` just needs to set `output_pos` to `0`?](https://docs.rs/csv-core/latest/src/csv_core/reader.rs.html#485-490)

Patches are welcome.

Fix patch:
diff --git a/csv-core/src/reader.rs b/csv-core/src/reader.rs
index dbd6dc3d..5e4e2916 100644
--- a/csv-core/src/reader.rs
+++ b/csv-core/src/reader.rs
@@ -487,6 +487,7 @@ impl Reader {
         self.nfa_state = NfaState::StartRecord;
         self.line = 1;
         self.has_read = false;
+        self.output_pos = 0;
     }
 
     /// Return the current line number as measured by the number of occurrences
@@ -2002,4 +2003,27 @@ mod tests {
 
         assert_read_record!(rdr, &inp, out, ends, 0, 0, 0, End);
     }
+
+    #[test]
+    fn reset_input_partial() {
+        use crate::ReadRecordResult::*;
+
+        let inp = b("foo,bar\nbaz");
+        let out = &mut [0; 1024];
+        let ends = &mut [0; 10];
+        let mut rdr = Reader::new();
+
+        assert_read_record!(rdr, &inp, out, ends, 8, 6, 2, Record);
+
+        // Try to read incomplete record.
+        let (result, _, _, _) = rdr.read_record(&inp[8..], out, ends);
+        assert_eq!(result, InputEmpty);
+
+        rdr.reset();
+
+        let inp = b("baz,raz\n");
+        let (result, _, _, _) = rdr.read_record(inp, out, ends);
+        assert_eq!(result, Record);
+        assert_eq!(ends[0], 3);
+    }
 }


Test patch: