diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index ce009e3ef..a63aa5be2 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -27,3 +27,13 @@ XmlReport::XmlReport(const QString &filename, QObject * parent) : { } +QString XmlReport::quoteMessage(const QString &message) +{ + QString quotedMessage(message); + quotedMessage.replace("&", "&"); + quotedMessage.replace("\"", """); + quotedMessage.replace("'", "'"); + quotedMessage.replace("<", "<"); + quotedMessage.replace(">", ">"); + return quotedMessage; +} diff --git a/gui/xmlreport.h b/gui/xmlreport.h index b1afd192f..bb94bb79b 100644 --- a/gui/xmlreport.h +++ b/gui/xmlreport.h @@ -35,6 +35,13 @@ class XmlReport : public Report { public: XmlReport(const QString &filename, QObject * parent = 0); + + /** + * @brief Quote the message. + * @param message Message to quote. + * @return quoted message. + */ + static QString quoteMessage(const QString &message); }; /// @} diff --git a/gui/xmlreportv1.cpp b/gui/xmlreportv1.cpp index 9fa8cbfd3..7fdf2d5fb 100644 --- a/gui/xmlreportv1.cpp +++ b/gui/xmlreportv1.cpp @@ -25,6 +25,7 @@ #include #include "report.h" #include "erroritem.h" +#include "xmlreport.h" #include "xmlreportv1.h" static const char ResultElementName[] = "results"; @@ -93,13 +94,15 @@ void XmlReportV1::WriteError(const ErrorItem &error) */ mXmlWriter->writeStartElement(ErrorElementName); - const QString file = QDir::toNativeSeparators(error.files[error.files.size() - 1]); + QString file = QDir::toNativeSeparators(error.files[error.files.size() - 1]); + file = XmlReport::quoteMessage(file); mXmlWriter->writeAttribute(FilenameAttribute, file); const QString line = QString::number(error.lines[error.lines.size() - 1]); mXmlWriter->writeAttribute(LineAttribute, line); mXmlWriter->writeAttribute(IdAttribute, error.id); mXmlWriter->writeAttribute(SeverityAttribute, error.severity); - mXmlWriter->writeAttribute(MsgAttribute, error.message); + const QString message = XmlReport::quoteMessage(error.message); + mXmlWriter->writeAttribute(MsgAttribute, message); mXmlWriter->writeEndElement(); } diff --git a/gui/xmlreportv2.cpp b/gui/xmlreportv2.cpp index 4caf7d05e..6c4fc088f 100644 --- a/gui/xmlreportv2.cpp +++ b/gui/xmlreportv2.cpp @@ -25,6 +25,7 @@ #include #include "report.h" #include "erroritem.h" +#include "xmlreport.h" #include "xmlreportv2.h" #include "cppcheck.h" @@ -110,14 +111,17 @@ void XmlReportV2::WriteError(const ErrorItem &error) mXmlWriter->writeStartElement(ErrorElementName); mXmlWriter->writeAttribute(IdAttribute, error.id); mXmlWriter->writeAttribute(SeverityAttribute, error.severity); - mXmlWriter->writeAttribute(MsgAttribute, error.summary); - mXmlWriter->writeAttribute(VerboseAttribute, error.message); + const QString summary = XmlReport::quoteMessage(error.summary); + mXmlWriter->writeAttribute(MsgAttribute, summary); + const QString message = XmlReport::quoteMessage(error.message); + mXmlWriter->writeAttribute(VerboseAttribute, message); for (int i = 0; i < error.files.count(); i++) { mXmlWriter->writeStartElement(LocationElementName); - const QString file = QDir::toNativeSeparators(error.files[i]); + QString file = QDir::toNativeSeparators(error.files[i]); + file = XmlReport::quoteMessage(file); mXmlWriter->writeAttribute(FilenameAttribute, file); const QString line = QString::number(error.lines[i]); mXmlWriter->writeAttribute(LineAttribute, line);