Skip to content

Commit

Permalink
chunks parser: add missing "null" case for chunk parser
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-codecov committed Jul 31, 2024
1 parent 72eddc6 commit 573d6f7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/parsers/pyreport/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,19 @@ where
// New chunk, start back at line 0.
buf.state.chunk.current_line = 0;

let report_lines: Vec<_> = preceded(
let empty_chunk = terminated("null", peek(alt((eof, "\n")))).map(|_| Vec::new());
let report_lines = preceded(
cut_err(chunk_header),
cut_err(separated(1.., report_line_or_empty, '\n')),
)
.context(StrContext::Label("chunk"))
.parse_next(buf)?;
let report_lines: Vec<ReportLine> = report_lines.into_iter().flatten().collect();
);

let parsed_lines: Vec<_> = alt((empty_chunk, report_lines))
.context(StrContext::Label("chunk"))
.parse_next(buf)?;

let parsed_lines: Vec<ReportLine> = parsed_lines.into_iter().flatten().collect();

utils::save_report_lines(report_lines.as_slice(), &mut buf.state)
utils::save_report_lines(parsed_lines.as_slice(), &mut buf.state)
.map_err(|e| ErrMode::from_external_error(buf, ErrorKind::Fail, e))?;

// Advance our chunk index so we can associate the data from the next chunk with
Expand Down Expand Up @@ -1876,6 +1880,8 @@ mod tests {
"{}\n[1, null, [[0, 1]]]\n<<<<< end_of_chunk >>>>>\n\n",
(Ok(()), 2),
),
// Chunks can have no header or report lines and only the text "null"
("null\n", (Ok(()), 0)),
// Malformed
// Missing newline after header
(
Expand Down

0 comments on commit 573d6f7

Please sign in to comment.