diff --git a/src/reader.rs b/src/reader.rs index 82f5d2c..9adeab8 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1606,7 +1606,8 @@ impl Reader { } return result; } - } else if self.state.trim.should_trim_fields() { + } + if self.state.trim.should_trim_fields() { record.trim(); } Ok(ok) @@ -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");