Skip to content

Commit

Permalink
Handle rows with empty cells as non-empty lines (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sekko27 authored Sep 21, 2023
1 parent d6166be commit 410f9e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export class CSVReader {

if (!this.inColumn && this.hasNext(this.columnSeparator)) {
this.debug("columnSeparator");
this.emptyLine = false;
this.processColumn();
this.skip(this.columnSeparator.length);
continue;
Expand Down
19 changes: 19 additions & 0 deletions reader_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,22 @@ a,b,c
assertEquals(rows, [["1", "2", "3"]]);
},
});

Deno.test({
name: "readCSVRows can read empty lines (not prepends to the next line)",
async fn() {
const reader = new MyReader(
`col1,col2,col3
a,b,c
,,
d,e,f`,
);
const rows = await asyncArrayFrom(readCSVRows(reader));
assertEquals(rows, [
["col1", "col2", "col3"],
["a", "b", "c"],
["", "", ""],
["d", "e", "f"],
]);
},
});

0 comments on commit 410f9e0

Please sign in to comment.