From f279fcd351e5331551b34ab0f7c26730eb0af068 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 5 Feb 2011 16:07:59 +0200 Subject: [PATCH] GUI: Unquote special characters when reading XML. Unquote the quoted data from XML file when reading. We don't want quoted chars to be visible in the GUI. --- gui/xmlreport.cpp | 11 +++++++++++ gui/xmlreport.h | 7 +++++++ gui/xmlreportv1.cpp | 8 +++++--- gui/xmlreportv2.cpp | 9 ++++++--- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index c3cc521d3..dc8f4be30 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -42,6 +42,17 @@ QString XmlReport::quoteMessage(const QString &message) return quotedMessage; } +QString XmlReport::unquoteMessage(const QString &message) +{ + QString quotedMessage(message); + quotedMessage.replace("&", "&"); + quotedMessage.replace(""", "\""); + quotedMessage.replace("'", "'"); + quotedMessage.replace("<", "<"); + quotedMessage.replace(">", ">"); + return quotedMessage; +} + int XmlReport::determineVersion(const QString &filename) { QFile file; diff --git a/gui/xmlreport.h b/gui/xmlreport.h index e0e4e55ba..74d2107d8 100644 --- a/gui/xmlreport.h +++ b/gui/xmlreport.h @@ -50,6 +50,13 @@ public: */ static QString quoteMessage(const QString &message); + /** + * @brief Unquote the message. + * @param message Message to quote. + * @return quoted message. + */ + static QString unquoteMessage(const QString &message); + /** * @brief Get the XML report format version from the file. * @param filename Filename of the report file. diff --git a/gui/xmlreportv1.cpp b/gui/xmlreportv1.cpp index 8df2a89da..1062de07f 100644 --- a/gui/xmlreportv1.cpp +++ b/gui/xmlreportv1.cpp @@ -158,7 +158,8 @@ ErrorItem XmlReportV1::ReadError(QXmlStreamReader *reader) if (reader->name().toString() == ErrorElementName) { QXmlStreamAttributes attribs = reader->attributes(); - const QString file = attribs.value("", FilenameAttribute).toString(); + QString file = attribs.value("", FilenameAttribute).toString(); + file = XmlReport::unquoteMessage(file); item.file = file; item.files.push_back(file); const int line = attribs.value("", LineAttribute).toString().toUInt(); @@ -174,8 +175,9 @@ ErrorItem XmlReportV1::ReadError(QXmlStreamReader *reader) const int ind = summary.indexOf('.'); if (ind != -1) summary = summary.left(ind + 1); - item.summary = summary; - item.message = attribs.value("", MsgAttribute).toString(); + item.summary = XmlReport::unquoteMessage(summary); + QString message = attribs.value("", MsgAttribute).toString(); + item.message = XmlReport::unquoteMessage(message); } return item; } diff --git a/gui/xmlreportv2.cpp b/gui/xmlreportv2.cpp index e6068ed8c..6088ea9a5 100644 --- a/gui/xmlreportv2.cpp +++ b/gui/xmlreportv2.cpp @@ -195,8 +195,10 @@ ErrorItem XmlReportV2::ReadError(QXmlStreamReader *reader) QXmlStreamAttributes attribs = reader->attributes(); item.id = attribs.value("", IdAttribute).toString(); item.severity = attribs.value("", SeverityAttribute).toString(); - item.summary = attribs.value("", MsgAttribute).toString(); - item.message = attribs.value("", VerboseAttribute).toString(); + const QString summary = attribs.value("", MsgAttribute).toString(); + item.summary = XmlReport::unquoteMessage(summary); + const QString message = attribs.value("", VerboseAttribute).toString(); + item.message = XmlReport::unquoteMessage(message); ReadLocations(item); } @@ -216,7 +218,8 @@ void XmlReportV2::ReadLocations(ErrorItem &item) continue; // Skip other than location elements { QXmlStreamAttributes attribs = mXmlReader->attributes(); - const QString file = attribs.value("", FilenameAttribute).toString(); + QString file = attribs.value("", FilenameAttribute).toString(); + file = XmlReport::unquoteMessage(file); if (item.file.isEmpty()) item.file = file; item.files.push_back(file);