Fixed #8906 (Encoding error in XML message: info attribute)

This commit is contained in:
Daniel Marjamäki 2019-01-02 18:22:12 +01:00
parent af639e9848
commit 7a40b85531
2 changed files with 3 additions and 2 deletions

View File

@ -396,7 +396,7 @@ std::string ErrorLogger::ErrorMessage::toXML() const
printer.PushAttribute("file", (*it).getfile().c_str());
printer.PushAttribute("line", std::max((*it).line,0));
if (!it->getinfo().empty())
printer.PushAttribute("info", it->getinfo().c_str());
printer.PushAttribute("info", fixInvalidChars(it->getinfo()).c_str());
printer.CloseElement(false);
}
for (std::string::size_type pos = 0; pos < mSymbolNames.size();) {

View File

@ -197,6 +197,7 @@ private:
void ToXmlV2Locations() const {
std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 };
locs.back().setinfo("ä");
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
header += " <cppcheck version=\"";
@ -206,7 +207,7 @@ private:
ASSERT_EQUALS(" </errors>\n</results>", ErrorLogger::ErrorMessage::getXMLFooter());
std::string message(" <error id=\"errorId\" severity=\"error\"");
message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n";
message += " <location file=\"bar.cpp\" line=\"8\"/>\n";
message += " <location file=\"bar.cpp\" line=\"8\" info=\"\\303\\244\"/>\n";
message += " <location file=\"foo.cpp\" line=\"5\"/>\n </error>";
ASSERT_EQUALS(message, msg.toXML());
}