dbertoni 02/05/08 13:50:53
Modified: c/Tests/Harness XMLFileReporter.cpp
Log:
Make sure all necessary characters are escaped in content.
Revision Changes Path
1.15 +71 -28 xml-xalan/c/Tests/Harness/XMLFileReporter.cpp
Index: XMLFileReporter.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/Tests/Harness/XMLFileReporter.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- XMLFileReporter.cpp 3 May 2002 06:29:21 -0000 1.14
+++ XMLFileReporter.cpp 8 May 2002 20:50:53 -0000 1.15
@@ -270,7 +270,7 @@
void
-XMLFileReporter::logTestFileClose(const XalanDOMString& msg, const
XalanDOMString& result)
+XMLFileReporter::logTestFileClose(const XalanDOMString& /* msg */, const
XalanDOMString& /* result */)
{
if (isReady())
{
@@ -295,7 +295,7 @@
void
-XMLFileReporter::logTestCaseClose(const XalanDOMString& msg, const
XalanDOMString& result)
+XMLFileReporter::logTestCaseClose(const XalanDOMString& /* msg */, const
XalanDOMString& /* result */)
{
if (isReady())
{
@@ -335,20 +335,17 @@
}
void
-XMLFileReporter::logElementWAttrs(int level, const XalanDOMString& element,
Hashtable attrs, const XalanDOMString& msg)
+XMLFileReporter::logElementWAttrs(int /* level */, const XalanDOMString&
element, Hashtable attrs, const XalanDOMString& msg)
{
- if (isReady()
- && (element.empty() == 0)
- && (attrs.empty() == 0)
- )
+ if (isReady() && !element.empty()&& !attrs.empty())
{
- char tmp[20];
- sprintf(tmp, "%d", level);
+// char tmp[20];
+// sprintf(tmp, "%d", level);
//
// Took out this level attribute cuz we don't use it.
-// printToFile("<" + escapestring(element) + " " + ATTR_LEVEL + "=\""
+// printToFile("<" + element + " " + ATTR_LEVEL + "=\""
// + tmp + "\"");
- printToFile("<" + escapestring(element) + " ");
+ printToFile("<" + element + " ");
Hashtable::iterator theEnd = attrs.end();
@@ -362,34 +359,28 @@
printToFile(XalanDOMString(">"));
if (msg.empty() != 0)
printToFile(escapestring(msg));
- printToFile("</" + escapestring(element) + ">");
+ printToFile("</" + element + ">");
}
}
void
XMLFileReporter::logElement(const XalanDOMString& element, const
XalanDOMString& msg)
{
- if (isReady()
- && (element.empty() == 0)
- && (msg.empty() == 0)
- )
+ if (isReady() && !element.empty() && !msg.empty())
{
-
- const XalanDOMString escElement(escapestring(element));
- const XalanDOMString theElement("<" + escElement + ">" + msg + "</" +
escElement + ">");
- printToFile(theElement);
-
+ printToFile("<" + element + ">");
+ printToFile(escapestring(msg));
+ printToFile("</" + element + ">");
}
}
void
XMLFileReporter::logStatistic (int level, long lVal, double dVal, const
XalanDOMString& msg)
{
- char tmp[20];
-
-
if (isReady())
{
+ char tmp[40];
+
sprintf(tmp, "%d", level);
printToFile(STATISTIC_HDR + tmp + "\" " + ATTR_DESC + "=\"" +
escapestring(msg) + "\">");
@@ -551,6 +542,32 @@
}
+
+static const XalanDOMChar theAmpersandString[] =
+{
+ XalanUnicode::charAmpersand,
+ XalanUnicode::charLetter_a,
+ XalanUnicode::charLetter_m,
+ XalanUnicode::charLetter_p,
+ XalanUnicode::charSemicolon,
+ 0
+};
+
+
+
+static const XalanDOMChar theApostropheString[] =
+{
+ XalanUnicode::charAmpersand,
+ XalanUnicode::charLetter_a,
+ XalanUnicode::charLetter_p,
+ XalanUnicode::charLetter_o,
+ XalanUnicode::charLetter_s,
+ XalanUnicode::charSemicolon,
+ 0
+};
+
+
+
static const XalanDOMChar theLessThanString[] =
{
XalanUnicode::charAmpersand,
@@ -561,6 +578,7 @@
};
+
static const XalanDOMChar theGreaterThanString[] =
{
XalanUnicode::charAmpersand,
@@ -572,14 +590,29 @@
+static const XalanDOMChar theQuoteString[] =
+{
+ XalanUnicode::charAmpersand,
+ XalanUnicode::charLetter_q,
+ XalanUnicode::charLetter_u,
+ XalanUnicode::charLetter_o,
+ XalanUnicode::charLetter_t,
+ XalanUnicode::charSemicolon,
+ 0
+};
+
+
+
XalanDOMString
XMLFileReporter::escapestring(const XalanDOMString& s)
{
XalanDOMString sb;
- const unsigned int length = s.length();
+ const XalanDOMString::size_type length = s.length();
+
+ sb.reserve(length);
- for (unsigned int i = 0; i < length; i++)
+ for (XalanDOMString::size_type i = 0; i < length; i++)
{
const XalanDOMChar ch = charAt(s, i);
@@ -591,8 +624,18 @@
{
append(sb, theGreaterThanString);
}
- // Note: Skipping escaping of UTF-16 surrogates and & ampersands,
since
- // I don't think we'll be outputting them or they won't affect our
output
+ else if (XalanUnicode::charAmpersand == ch)
+ {
+ append(sb, theAmpersandString);
+ }
+ else if (XalanUnicode::charQuoteMark == ch)
+ {
+ append(sb, theQuoteString);
+ }
+ else if (XalanUnicode::charApostrophe == ch)
+ {
+ append(sb, theApostropheString);
+ }
else
{
append(sb, ch);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]