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.
This commit is contained in:
Kimmo Varis 2011-02-05 16:07:59 +02:00
parent 9eacceb00a
commit f279fcd351
4 changed files with 29 additions and 6 deletions

View File

@ -42,6 +42,17 @@ QString XmlReport::quoteMessage(const QString &message)
return quotedMessage; return quotedMessage;
} }
QString XmlReport::unquoteMessage(const QString &message)
{
QString quotedMessage(message);
quotedMessage.replace("&", "&");
quotedMessage.replace(""", "\"");
quotedMessage.replace("'", "'");
quotedMessage.replace("&lt;", "<");
quotedMessage.replace("&gt;", ">");
return quotedMessage;
}
int XmlReport::determineVersion(const QString &filename) int XmlReport::determineVersion(const QString &filename)
{ {
QFile file; QFile file;

View File

@ -50,6 +50,13 @@ public:
*/ */
static QString quoteMessage(const QString &message); 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. * @brief Get the XML report format version from the file.
* @param filename Filename of the report file. * @param filename Filename of the report file.

View File

@ -158,7 +158,8 @@ ErrorItem XmlReportV1::ReadError(QXmlStreamReader *reader)
if (reader->name().toString() == ErrorElementName) if (reader->name().toString() == ErrorElementName)
{ {
QXmlStreamAttributes attribs = reader->attributes(); 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.file = file;
item.files.push_back(file); item.files.push_back(file);
const int line = attribs.value("", LineAttribute).toString().toUInt(); const int line = attribs.value("", LineAttribute).toString().toUInt();
@ -174,8 +175,9 @@ ErrorItem XmlReportV1::ReadError(QXmlStreamReader *reader)
const int ind = summary.indexOf('.'); const int ind = summary.indexOf('.');
if (ind != -1) if (ind != -1)
summary = summary.left(ind + 1); summary = summary.left(ind + 1);
item.summary = summary; item.summary = XmlReport::unquoteMessage(summary);
item.message = attribs.value("", MsgAttribute).toString(); QString message = attribs.value("", MsgAttribute).toString();
item.message = XmlReport::unquoteMessage(message);
} }
return item; return item;
} }

View File

@ -195,8 +195,10 @@ ErrorItem XmlReportV2::ReadError(QXmlStreamReader *reader)
QXmlStreamAttributes attribs = reader->attributes(); QXmlStreamAttributes attribs = reader->attributes();
item.id = attribs.value("", IdAttribute).toString(); item.id = attribs.value("", IdAttribute).toString();
item.severity = attribs.value("", SeverityAttribute).toString(); item.severity = attribs.value("", SeverityAttribute).toString();
item.summary = attribs.value("", MsgAttribute).toString(); const QString summary = attribs.value("", MsgAttribute).toString();
item.message = attribs.value("", VerboseAttribute).toString(); item.summary = XmlReport::unquoteMessage(summary);
const QString message = attribs.value("", VerboseAttribute).toString();
item.message = XmlReport::unquoteMessage(message);
ReadLocations(item); ReadLocations(item);
} }
@ -216,7 +218,8 @@ void XmlReportV2::ReadLocations(ErrorItem &item)
continue; // Skip other than location elements continue; // Skip other than location elements
{ {
QXmlStreamAttributes attribs = mXmlReader->attributes(); 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()) if (item.file.isEmpty())
item.file = file; item.file = file;
item.files.push_back(file); item.files.push_back(file);