diff --git a/include/internal/basic_csv_parser.cpp b/include/internal/basic_csv_parser.cpp index 61b8f35..6e5ea33 100644 --- a/include/internal/basic_csv_parser.cpp +++ b/include/internal/basic_csv_parser.cpp @@ -143,9 +143,11 @@ namespace csv { while (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE) this->data_pos++; - // End of record -> Write record - this->push_field(); - this->push_row(); + // End of record -> Write non-empty record + if (this->field_length > 0 || !this->current_row.empty()) { + this->push_field(); + this->push_row(); + } // Reset this->current_row = CSVRow(data_ptr, this->data_pos, fields->size()); diff --git a/single_include/csv.hpp b/single_include/csv.hpp index 3571bbb..473c3cb 100644 --- a/single_include/csv.hpp +++ b/single_include/csv.hpp @@ -7084,9 +7084,11 @@ namespace csv { while (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE) this->data_pos++; - // End of record -> Write record - this->push_field(); - this->push_row(); + // End of record -> Write non-empty record + if (this->field_length > 0 || !this->current_row.empty()) { + this->push_field(); + this->push_row(); + } // Reset this->current_row = CSVRow(data_ptr, this->data_pos, fields->size()); diff --git a/single_include_test/csv.hpp b/single_include_test/csv.hpp index 21a5a56..afbcef2 100644 --- a/single_include_test/csv.hpp +++ b/single_include_test/csv.hpp @@ -7084,9 +7084,11 @@ namespace csv { while (this->data_pos < in.size() && parse_flag(in[this->data_pos]) == ParseFlags::NEWLINE) this->data_pos++; - // End of record -> Write record - this->push_field(); - this->push_row(); + // End of record -> Write non-empty record + if (this->field_length > 0 || !this->current_row.empty()) { + this->push_field(); + this->push_row(); + } // Reset this->current_row = CSVRow(data_ptr, this->data_pos, fields->size());