Fix 'csv writer generates invalid file in case field delimiter is used in any field'
ClosedPublic

Authored by habacker on Jun 4 2018, 1:14 PM.

Details

Summary

This commit fixes all fields which may have field separators like
payee, acccount, category, memo, number and money related fields.

As goodie the commit also handle double quotes inside memos.

Note: The previous implementation removes single quotes from memo fields,
which is now obsolate and may be reverted.

BUG:395025
FIXED-IN:4.8.3

Test Plan

compiled and exported to csv on linux

Diff Detail

Repository
R261 KMyMoney
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
habacker requested review of this revision.Jun 4 2018, 1:14 PM
habacker created this revision.
tbaumgart requested changes to this revision.Jun 4 2018, 1:26 PM
tbaumgart added a subscriber: tbaumgart.
tbaumgart added inline comments.
kmymoney/plugins/csvexport/csvwriter.cpp
448

Since you enclose in double quotes later on, you might as well leave the \n as they are.

449
m.replace(QLatin1Char('"'), QStringLiteral("\"\""));
450

I would write this as

return QString("\"%1\"%2").arg(m, m_separator);
460

You could make this a

const auto txt = ...
461

See format(QString)

This revision now requires changes to proceed.Jun 4 2018, 1:26 PM
habacker updated this revision to Diff 35588.Jun 5 2018, 8:16 AM
habacker edited the summary of this revision. (Show Details)
  • covers now additional columns
  • fix different precision of formatting money
  • use format() for mostly strings
habacker marked 5 inline comments as done.Jun 5 2018, 8:19 AM
habacker added inline comments.
kmymoney/plugins/csvexport/csvwriter.cpp
449

QStringLiteral is Qt5 only, I added support for KDE4 and KF5

tbaumgart accepted this revision.Jun 5 2018, 8:57 AM

Looks ok to me besides that one question. It looks like the original code does add an extra separator as well, but is this correct?

kmymoney/plugins/csvexport/csvwriter.cpp
250

Doesn't that leave an extra column at the end of the last entry?

449

True, I forgot. Don't do much Qt4 these days.

This revision is now accepted and ready to land.Jun 5 2018, 8:57 AM
habacker marked 4 inline comments as done.Jun 5 2018, 9:11 AM
habacker added inline comments.
kmymoney/plugins/csvexport/csvwriter.cpp
250

it does, same for investment lines at line 310: strStatus += m_separator;.

I will fix that before committing

habacker marked an inline comment as done.Jun 5 2018, 9:40 AM
habacker added inline comments.
kmymoney/plugins/csvexport/csvwriter.cpp
250

That extra field separator was already in the old code. and will be fixed in an additional commit along with the mentioned investment column number issue.

What we missed to see is that this commit adds an extra field separator in line 218, which I'm going to fix before committing.

This revision was automatically updated to reflect the committed changes.