Skip to content

Commit

Permalink
reader: tweak record trimming logic
Browse files Browse the repository at this point in the history
Fixes #237
  • Loading branch information
Salehbigdeli authored Nov 9, 2024
1 parent 06764b9 commit ce01ae7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,8 @@ impl<R: io::Read> Reader<R> {
}
return result;
}
} else if self.state.trim.should_trim_fields() {
}
if self.state.trim.should_trim_fields() {
record.trim();
}
Ok(ok)
Expand Down Expand Up @@ -2302,6 +2303,20 @@ mod tests {
}
}

#[test]
fn read_trimmed_records_without_headers() {
let data = b("a1, b1\t,\t c1\t\n");
let mut rdr = ReaderBuilder::new()
.has_headers(false)
.trim(Trim::All)
.from_reader(data);
let mut rec = ByteRecord::new();
assert!(rdr.read_byte_record(&mut rec).unwrap());
assert_eq!("a1", s(&rec[0]));
assert_eq!("b1", s(&rec[1]));
assert_eq!("c1", s(&rec[2]));
}

#[test]
fn read_record_unequal_fails() {
let data = b("foo\nbar,baz");
Expand Down

0 comments on commit ce01ae7

Please sign in to comment.