# HG changeset patch # User František Kučera # Date 1636800774 -3600 # Node ID 22eb4838e8d019c554c779c647da20961f95e821 # Parent 90ae67de2f68e08b0138d3f61472e54e148227ff check total number of values and throw exception if it does not match the number of columns diff -r 90ae67de2f68 -r 22eb4838e8d0 src/CSVCommand.cpp --- a/src/CSVCommand.cpp Sun Apr 18 18:20:09 2021 +0200 +++ b/src/CSVCommand.cpp Sat Nov 13 11:52:54 2021 +0100 @@ -134,12 +134,14 @@ vector metadata; bool headerDone = false; bool lastInRecord = false; + integer_t valueCount = 0; stringstream currentValue; while (readValue(input, currentValue, lastInRecord) && input.good()) { if (headerDone) { writer->writeAttribute(convertor.from_bytes(currentValue.str())); + valueCount++; } else { AttributeMetadata am; am.attributeName = convertor.from_bytes(currentValue.str()); @@ -173,6 +175,13 @@ currentValue.str(""); currentValue.clear(); } + + /** + * RFC 4180: + * - Each line should contain the same number of fields throughout the file. + * - The last field in the record must not be followed by a comma. + */ + if (valueCount % metadata.size()) throw RelpipeWriterException(L"The total number of values " + std::to_wstring(valueCount) + L" does not match the number of declared columns " + std::to_wstring(metadata.size())); } }