From 8dec28ff4f1176b485d9de722756c677be3a4f1c Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 26 Aug 2026 16:44:45 +0200 Subject: fix: harden candidate appends and cover the message-row sender roles --- src/businesssenders.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/businesssenders.cpp') diff --git a/src/businesssenders.cpp b/src/businesssenders.cpp index 06f4d43..ab9394d 100644 --- a/src/businesssenders.cpp +++ b/src/businesssenders.cpp @@ -102,10 +102,17 @@ void appendCandidates(const QString &path, const QHash &counts) // from parse() above, which deliberately drops comments: here a comment is // exactly what must be remembered. QSet mentioned; + bool needsLeadingNewline = false; QFile existing(path); if (existing.open(QIODevice::ReadOnly | QIODevice::Text)) { - const QStringList lines = - QString::fromUtf8(existing.readAll()).split(QLatin1Char('\n')); + const QString contents = QString::fromUtf8(existing.readAll()); + // Hand-editing (the documented workflow) can leave the file without a + // trailing newline; appending then glues the first addition onto the + // last entry and silently breaks it. Write a newline before the + // additions in that case. + if (!contents.isEmpty() && !contents.endsWith(QLatin1Char('\n'))) + needsLeadingNewline = true; + const QStringList lines = contents.split(QLatin1Char('\n')); for (const QString &raw : lines) { QString line = raw.trimmed(); if (line.startsWith(QLatin1Char('#'))) @@ -140,6 +147,8 @@ void appendCandidates(const QString &path, const QHash &counts) if (!file.open(QIODevice::Append | QIODevice::Text)) return; QTextStream out(&file); + if (needsLeadingNewline) + out << '\n'; for (const QString &line : additions) out << line << '\n'; } -- cgit v1.2.3