Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dataset
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@ BaseCSVReader::parse_result_t BaseCSVReader::parseCSV(Driver& driver) {
return {curRowIdx, numErrors};
}
column++;
} else if (column > 0) {
// File ends right after a delimiter with an empty trailing field.
// Without this, a row like "a,b," (no trailing newline) loses its last
// empty field and undercounts columns, causing "expected N, got N-1".
if (!addValue(driver, curRowIdx, column, std::string_view{}, escapePositions)) {
return {curRowIdx, numErrors};
}
column++;
}
if (column > 0) {
curRowIdx += driver.addRow(curRowIdx, column,
Expand Down
19 changes: 19 additions & 0 deletions test/test_files/csv/issues_trailing_empty_field_eof.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-DATASET CSV empty

--

# Regression test for the fix in ffce93a49c306806a546b3cd368bc50849c87688
# "fix(csv): handle trailing empty field at EOF without newline"
#
# When a CSV file ends with a row like "a,b," (no trailing newline, last field
# empty), the parser used to drop the empty field, causing "expected N values
# per row, but got N-1". The fix adds an else-if branch in final_state to emit
# the empty value when column > 0.
-CASE TrailingEmptyFieldAtEOF
-STATEMENT CREATE NODE TABLE t(A STRING, B STRING, C STRING, PRIMARY KEY(A));
---- ok
-STATEMENT COPY t FROM "${LBUG_ROOT_DIRECTORY}/dataset/csv-edge-case-tests/trailing-empty-field-eof.csv";
---- ok
-STATEMENT MATCH (t:t) RETURN t.*;
---- 1
a|b|
Loading