Skip to content

Commit

Permalink
json: ensure to only write non-empty records so we don't produce an…
Browse files Browse the repository at this point in the history
… invalid CSV
  • Loading branch information
jqnatividad committed Jul 29, 2024
1 parent e3ac7ab commit acdd259
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cmd/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
let mut final_csv_wtr = config::Config::new(&args.flag_output).writer()?;
final_csv_wtr.write_record(sel.iter().map(|&i| &byteheaders[i]))?;
while intermediate_csv_rdr.read_byte_record(&mut record)? {
final_csv_wtr.write_record(sel.iter().map(|&i| &record[i]))?;
if !record.is_empty() {
final_csv_wtr.write_record(sel.iter().map(|&i| &record[i]))?;
}
}

Ok(final_csv_wtr.flush()?)
Expand Down

0 comments on commit acdd259

Please sign in to comment.