Fixed #854 (invalid XML generated for folders containing &)
This commit is contained in:
parent
45b0758e71
commit
8e3123ec1c
|
@ -124,36 +124,37 @@ std::string ErrorLogger::ErrorMessage::getXMLFooter()
|
|||
return "</results>";
|
||||
}
|
||||
|
||||
static std::string stringToXml(std::string s)
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = s.find_first_of("<>&\"", pos)) != std::string::npos)
|
||||
{
|
||||
if (s[pos] == '<')
|
||||
s.insert(pos + 1, "<");
|
||||
else if (s[pos] == '>')
|
||||
s.insert(pos + 1, ">");
|
||||
else if (s[pos] == '&')
|
||||
s.insert(pos + 1, "&");
|
||||
else if (s[pos] == '"')
|
||||
s.insert(pos + 1, """);
|
||||
s.erase(pos, 1);
|
||||
++pos;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ErrorLogger::ErrorMessage::toXML() const
|
||||
{
|
||||
std::ostringstream xml;
|
||||
xml << "<error";
|
||||
if (!_callStack.empty())
|
||||
{
|
||||
xml << " file=\"" << _callStack.back().getfile() << "\"";
|
||||
xml << " file=\"" << stringToXml(_callStack.back().getfile()) << "\"";
|
||||
xml << " line=\"" << _callStack.back().line << "\"";
|
||||
}
|
||||
xml << " id=\"" << _id << "\"";
|
||||
xml << " severity=\"" << _severity << "\"";
|
||||
|
||||
// Replace characters in message
|
||||
std::string m(_msg);
|
||||
std::string::size_type pos = 0;
|
||||
while ((pos = m.find_first_of("<>&\"", pos)) != std::string::npos)
|
||||
{
|
||||
if (m[pos] == '<')
|
||||
m.insert(pos + 1, "<");
|
||||
else if (m[pos] == '>')
|
||||
m.insert(pos + 1, ">");
|
||||
else if (m[pos] == '&')
|
||||
m.insert(pos + 1, "&");
|
||||
else if (m[pos] == '"')
|
||||
m.insert(pos + 1, """);
|
||||
m.erase(pos, 1);
|
||||
++pos;
|
||||
}
|
||||
|
||||
xml << " msg=\"" << m << "\"";
|
||||
xml << " msg=\"" << stringToXml(_msg) << "\"";
|
||||
xml << "/>";
|
||||
return xml.str();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue