Skip to content

Commit f2cba42

Browse files
committed
fix: skip last line in comment
BurntSushi#363
1 parent 7b2be38 commit f2cba42

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

csv-core/src/reader.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ impl Reader {
752752
// parsing a new record, then we should sink into the final state
753753
// and never move from there. (pro-tip: the start state doubles as
754754
// the final state!)
755-
if state >= self.dfa.final_record || state.is_start() {
755+
if state >= self.dfa.final_record || state.is_start() || state == self.dfa.in_comment {
756756
self.dfa.new_state_final_end()
757757
} else {
758758
self.dfa.new_state_final_record()
@@ -1116,6 +1116,8 @@ struct Dfa {
11161116
in_field: DfaState,
11171117
/// The DFA state corresponding to being inside an quoted field.
11181118
in_quoted: DfaState,
1119+
/// The DFA state corresponding to being inside a comment.
1120+
in_comment: DfaState,
11191121
/// The minimum DFA state that indicates a field has been parsed. All DFA
11201122
/// states greater than this are also final-field states.
11211123
final_field: DfaState,
@@ -1132,6 +1134,7 @@ impl Dfa {
11321134
classes: DfaClasses::new(),
11331135
in_field: DfaState(0),
11341136
in_quoted: DfaState(0),
1137+
in_comment: DfaState(0),
11351138
final_field: DfaState(0),
11361139
final_record: DfaState(0),
11371140
}
@@ -1167,6 +1170,7 @@ impl Dfa {
11671170
fn finish(&mut self) {
11681171
self.in_field = self.new_state(NfaState::InField);
11691172
self.in_quoted = self.new_state(NfaState::InQuotedField);
1173+
self.in_comment = self.new_state(NfaState::InComment);
11701174
self.final_field = self.new_state(NfaState::EndFieldDelim);
11711175
self.final_record = self.new_state(NfaState::EndRecord);
11721176
}

0 commit comments

Comments
 (0)