GUI: Quote special chars in the XML output.
Fixes ticket #2543 (GUI: Xml report does not quote special characters)
This commit is contained in:
parent
df231aa738
commit
299e200d45
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
/// @}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QDebug>
|
||||
#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();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QDebug>
|
||||
#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);
|
||||
|
|
Loading…
Reference in New Issue