diff --git a/autotests/importexportvcardtest.h b/autotests/importexportvcardtest.h --- a/autotests/importexportvcardtest.h +++ b/autotests/importexportvcardtest.h @@ -33,6 +33,7 @@ void shouldExportFullTestVcard4(); void shouldExportMiscElementVcard4(); void shouldExportMemberElementVcard4(); + void shouldExportMissingNewlineVcard4(); }; #endif // IMPORTEXPORTVCARDTEST_H diff --git a/autotests/importexportvcardtest.cpp b/autotests/importexportvcardtest.cpp --- a/autotests/importexportvcardtest.cpp +++ b/autotests/importexportvcardtest.cpp @@ -197,6 +197,30 @@ compareBuffers(result, vcardexpected); } +void ImportExportVCardTest::shouldExportMissingNewlineVcard4() +{ + QByteArray vcarddata("BEGIN:VCARD" + "VERSION:4.0\r\n" + "KIND:group\r\n" + "FN:Funky distribution list\r\n" + "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\r\n" + "END:VCARD"); + + QByteArray vcardexpected("BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "FN:Funky distribution list\r\n" + "KIND:group\r\n" + "N:;;;;\r\n" + "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\r\n" + "END:VCARD\r\n\r\n"); + + KContacts::VCardTool vcard; + const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); + + const QByteArray result = vcard.exportVCards(lst, KContacts::VCard::v4_0); + compareBuffers(result, vcardexpected); +} + // TODO please make this data driven before copy/pasting more methods here... QTEST_MAIN(ImportExportVCardTest) diff --git a/src/vcardparser/vcardparser.cpp b/src/vcardparser/vcardparser.cpp --- a/src/vcardparser/vcardparser.cpp +++ b/src/vcardparser/vcardparser.cpp @@ -276,7 +276,7 @@ bool inVCard = false; StringCache cache; - for (; lineEnd != -1; lineStart = lineEnd + 1, lineEnd = text.indexOf('\n', lineStart)) { + for (; lineStart != text.size() + 1; lineStart = lineEnd + 1, lineEnd = (text.indexOf('\n', lineStart) == -1) ? text.size() : text.indexOf('\n', lineStart)) { QByteArray cur = text.mid(lineStart, lineEnd - lineStart); // remove the trailing \r, left from \r\n if (cur.endsWith('\r')) {