Fix ticket #397 (xml output doesn't encode " and & -characters as it should)

http://sourceforge.net/apps/trac/cppcheck/ticket/397
This commit is contained in:
Reijo Tomperi 2009-06-12 22:02:01 +03:00
parent 799252e8f2
commit 9ea80b4d74
2 changed files with 13 additions and 6 deletions

View File

@ -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);

View File

@ -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, "&lt;");
if (m[pos] == '>')
else if (m[pos] == '>')
m.insert(pos + 1, "&gt;");
else if (m[pos] == '&')
m.insert(pos + 1, "&amp;");
else if (m[pos] == '"')
m.insert(pos + 1, "&quot;");
m.erase(pos, 1);
++pos;
}
xml << " msg=\"" << m << "\"";