Author: jkupec
Date: Mon Feb 25 13:51:14 2008
New Revision: 8899
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8899&view=rev
Log:
- encode xml special chars
Modified:
trunk/zypper/src/output/OutXML.cc
Modified: trunk/zypper/src/output/OutXML.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/OutXML.cc?rev=8899&r1=8898&r2=8899&view=diff
==============================================================================
--- trunk/zypper/src/output/OutXML.cc (original)
+++ trunk/zypper/src/output/OutXML.cc Mon Feb 25 13:51:14 2008
@@ -36,24 +36,55 @@
return false;
}
+string xmlEncode(const string & s)
+{
+ string result;
+ result.reserve(s.size()*2);
+ char buff[7];
+
+ for(string::const_iterator it = s.begin(); it != s.end(); ++it)
+ {
+ switch(*it)
+ {
+ case '&':
+ case '<':
+ case '>':
+ case '"':
+ {
+ snprintf(buff, 7, "%d;", (unsigned)*it);
+ result.append(buff);
+ break;
+ }
+ default:
+ result.append(1, *it);
+ }
+ }
+
+ return result;
+}
+
void OutXML::info(const string & msg, Verbosity verbosity, Type mask)
{
if (infoWarningFilter(verbosity, mask))
return;
- //! \todo xml escape the msg
- cout << "" << msg << "</message>" << endl;
+
+ cout << "" << xmlEncode(msg)
+ << "</message>" << endl;
}
void OutXML::warning(const string & msg, Verbosity verbosity, Type mask)
{
if (infoWarningFilter(verbosity, mask))
return;
- cout << "" << msg << "</message>" << endl;
+
+ cout << "" << xmlEncode(msg)
+ << "</message>" << endl;
}
void OutXML::error(const string & problem_desc, const string & hint)
{
- cout << "" << problem_desc << "</message>" << endl;
+ cout << "" << xmlEncode(problem_desc)
+ << "</message>" << endl;
//! \todo hint
}
@@ -71,15 +102,16 @@
if (!hint.empty())
s << hint << endl;
- cout << "" << s.str() << "</message>" << endl;
+ cout << "" << xmlEncode(s.str())
+ << "</message>" << endl;
}
void OutXML::writeProgressTag(const string & id, const string & label,
int value, bool done, bool error)
{
cout << "