Skip to content

Commit ce01ae7

Browse files
authored
reader: tweak record trimming logic
Fixes BurntSushi#237
1 parent 06764b9 commit ce01ae7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/reader.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,8 @@ impl<R: io::Read> Reader<R> {
16061606
}
16071607
return result;
16081608
}
1609-
} else if self.state.trim.should_trim_fields() {
1609+
}
1610+
if self.state.trim.should_trim_fields() {
16101611
record.trim();
16111612
}
16121613
Ok(ok)
@@ -2302,6 +2303,20 @@ mod tests {
23022303
}
23032304
}
23042305

2306+
#[test]
2307+
fn read_trimmed_records_without_headers() {
2308+
let data = b("a1, b1\t,\t c1\t\n");
2309+
let mut rdr = ReaderBuilder::new()
2310+
.has_headers(false)
2311+
.trim(Trim::All)
2312+
.from_reader(data);
2313+
let mut rec = ByteRecord::new();
2314+
assert!(rdr.read_byte_record(&mut rec).unwrap());
2315+
assert_eq!("a1", s(&rec[0]));
2316+
assert_eq!("b1", s(&rec[1]));
2317+
assert_eq!("c1", s(&rec[2]));
2318+
}
2319+
23052320
#[test]
23062321
fn read_record_unequal_fails() {
23072322
let data = b("foo\nbar,baz");

0 commit comments

Comments
 (0)