From 9ea80b4d7478f3103edf86ca935a88ee4b94d12c Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Fri, 12 Jun 2009 22:02:01 +0300 Subject: [PATCH] Fix ticket #397 (xml output doesn't encode " and & -characters as it should) http://sourceforge.net/apps/trac/cppcheck/ticket/397 --- gui/mainwindow.cpp | 10 ++++++---- src/errorlogger.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 7bfc77e3a..d2895922a 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -460,13 +460,15 @@ void MainWindow::Save() bool xml = (dialog.selectedNameFilter() == filters[0]); //Force xml extension to the file - if (xml && !filename.endsWith(".xml", Qt::CaseInsensitive)) { - filename+=".xml"; + if (xml && !filename.endsWith(".xml", Qt::CaseInsensitive)) + { + filename += ".xml"; } //Force .txt extension - if (!xml && !filename.endsWith(".txt", Qt::CaseInsensitive)) { - filename+=".txt"; + if (!xml && !filename.endsWith(".txt", Qt::CaseInsensitive)) + { + filename += ".txt"; } mResults.Save(filename, xml); diff --git a/src/errorlogger.cpp b/src/errorlogger.cpp index cb72aef63..ca8f23d8d 100644 --- a/src/errorlogger.cpp +++ b/src/errorlogger.cpp @@ -128,13 +128,18 @@ std::string ErrorLogger::ErrorMessage::toXML() const // Replace characters in message std::string m(_msg); std::string::size_type pos = 0; - while ((pos = m.find_first_of("<>", pos)) != std::string::npos) + while ((pos = m.find_first_of("<>&\"", pos)) != std::string::npos) { if (m[pos] == '<') m.insert(pos + 1, "<"); - if (m[pos] == '>') + else if (m[pos] == '>') m.insert(pos + 1, ">"); + else if (m[pos] == '&') + m.insert(pos + 1, "&"); + else if (m[pos] == '"') + m.insert(pos + 1, """); m.erase(pos, 1); + ++pos; } xml << " msg=\"" << m << "\"";