From ab9b7ea1cc09a1e454ac2bc9e1ab66389bcc6645 Mon Sep 17 00:00:00 2001 From: myst6re Date: Thu, 4 Apr 2024 00:25:11 +0200 Subject: [PATCH] Fix csv escaping --- src/CsvFile.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/CsvFile.cpp b/src/CsvFile.cpp index b1c0a77..012eea5 100644 --- a/src/CsvFile.cpp +++ b/src/CsvFile.cpp @@ -128,12 +128,15 @@ bool CsvFile::readLine(QStringList &line) bool CsvFile::writeLine(const QStringList &line) { - QString l; + QString l, esc = QString().append(_quoteCharacter).append(_quoteCharacter); - for (const QString &field: line) { - l.append(_quoteCharacter).append(field).append(_quoteCharacter).append(_fieldSeparator); + for (QString field: line) { + l.append(_quoteCharacter) + .append(field.replace(_quoteCharacter, esc)) + .append(_quoteCharacter) + .append(_fieldSeparator); } - + l[l.size() - 1] = '\r'; l.append('\n');