vmassol 2005/05/05 02:21:54
Modified: framework/src/test/share-12-13-14/org/apache/cactus/internal/util
TestStringUtil.java
framework/src/java/share-12-13-14/org/apache/cactus/internal/util
StringUtil.java
framework/src/java/share-12-13-14/org/apache/cactus/internal/server/runner
XMLFormatter.java
documentation/docs/xdocs changes.xml
Log:
CACTUS-210: The XML Formatter in the Servlet Test Runner had a bug where it
was sometime cuting some characters from the test result string to format.
Thanks to Thorsten Harders.
Revision Changes Path
1.2 +17 -2
jakarta-cactus/framework/src/test/share-12-13-14/org/apache/cactus/internal/util/TestStringUtil.java
Index: TestStringUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/test/share-12-13-14/org/apache/cactus/internal/util/TestStringUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestStringUtil.java 22 May 2004 11:34:46 -0000 1.1
+++ TestStringUtil.java 5 May 2005 09:21:54 -0000 1.2
@@ -1,7 +1,7 @@
/*
* ========================================================================
*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,4 +83,19 @@
filterPatterns));
}
+ /**
+ * Verify character-replacement algorithm.
+ */
+ public void testReplace()
+ {
+ assertEquals("you&me",
+ StringUtil.replace("you&me", '&', "&"));
+ assertEquals("<tag",
+ StringUtil.replace("<tag", '<', "<"));
+ assertEquals("tag>",
+ StringUtil.replace("tag>", '>', ">"));
+ assertEquals("12<X>456<X>89",
+ StringUtil.replace("12x456x89", 'x', "<X>"));
+ }
+
}
1.2 +43 -2
jakarta-cactus/framework/src/java/share-12-13-14/org/apache/cactus/internal/util/StringUtil.java
Index: StringUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share-12-13-14/org/apache/cactus/internal/util/StringUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StringUtil.java 22 May 2004 11:34:48 -0000 1.1
+++ StringUtil.java 5 May 2005 09:21:54 -0000 1.2
@@ -1,7 +1,7 @@
/*
* ========================================================================
*
- * Copyright 2001-2003 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -124,4 +124,45 @@
return false;
}
+ /**
+ * Replaces a character in a string by a substring.
+ *
+ * @param theBaseString the base string in which to perform replacements
+ * @param theChar the char to look for
+ * @param theNewString the string with which to replace the char
+ * @return the string with replacements done or null if the input string
+ * was null
+ */
+ public static String replace(String theBaseString, char theChar,
+ String theNewString)
+ {
+ if (theBaseString == null)
+ {
+ return null;
+ }
+
+ int pos = theBaseString.indexOf(theChar);
+ if (pos < 0)
+ {
+ return theBaseString;
+ }
+
+ int lastPos = 0;
+ StringBuffer result = new StringBuffer();
+ while (pos > -1)
+ {
+ result.append(theBaseString.substring(lastPos, pos));
+ result.append(theNewString);
+
+ lastPos = pos + 1;
+ pos = theBaseString.indexOf(theChar, lastPos);
+ }
+
+ if (lastPos < theBaseString.length())
+ {
+ result.append(theBaseString.substring(lastPos));
+ }
+
+ return result.toString();
+ }
}
1.3 +6 -53
jakarta-cactus/framework/src/java/share-12-13-14/org/apache/cactus/internal/server/runner/XMLFormatter.java
Index: XMLFormatter.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share-12-13-14/org/apache/cactus/internal/server/runner/XMLFormatter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLFormatter.java 8 Aug 2004 09:04:08 -0000 1.2
+++ XMLFormatter.java 5 May 2005 09:21:54 -0000 1.3
@@ -1,7 +1,7 @@
/*
* ========================================================================
*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -302,59 +302,12 @@
// It is important to replace the "&" first as the other replacements
// also introduces "&" chars ...
- newString = XMLFormatter.replace(theString, '&', "&");
+ newString = StringUtil.replace(theString, '&', "&");
- newString = XMLFormatter.replace(newString, '<', "<");
- newString = XMLFormatter.replace(newString, '>', ">");
- newString = XMLFormatter.replace(newString, '\"', """);
+ newString = StringUtil.replace(newString, '<', "<");
+ newString = StringUtil.replace(newString, '>', ">");
+ newString = StringUtil.replace(newString, '\"', """);
return newString;
}
-
- /**
- * Replaces a character in a string by a substring.
- *
- * @param theBaseString the base string in which to perform replacements
- * @param theChar the char to look for
- * @param theNewString the string with which to replace the char
- * @return the string with replacements done or null if the input string
- * was null
- */
- private static String replace(String theBaseString, char theChar,
- String theNewString)
- {
- if (theBaseString == null)
- {
- return null;
- }
-
- final int len = theBaseString.length() - 1;
- int pos = -1;
-
- while ((pos = theBaseString.indexOf(theChar, pos + 1)) > -1)
- {
- if (pos == 0)
- {
- final String after = theBaseString.substring(1);
-
- theBaseString = theNewString + after;
- }
- else if (pos == len)
- {
- final String before = theBaseString.substring(0, pos);
-
- theBaseString = before + theNewString;
- }
- else
- {
- final String before = theBaseString.substring(0, pos);
- final String after = theBaseString.substring(pos + 1);
-
- theBaseString = before + theNewString + after;
- }
- }
-
- return theBaseString;
- }
-
}
1.216 +5 -0 jakarta-cactus/documentation/docs/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/changes.xml,v
retrieving revision 1.215
retrieving revision 1.216
diff -u -r1.215 -r1.216
--- changes.xml 21 Apr 2005 11:56:33 -0000 1.215
+++ changes.xml 5 May 2005 09:21:54 -0000 1.216
@@ -91,6 +91,11 @@
</devs>
<release version="1.8dev" date="in CVS">
+ <action dev="VMA" type="fix" issue="CACTUS-210" due-to="Thorsten
Harders">
+ The XML Formatter in the Servlet Test Runner had a bug where it
+ was sometime cuting some characters from the test result string
+ to format.
+ </action>
<action dev="FAL" type="fix" issue="CACTUS-204">
<code>CactifyWar</code> task now does not require a <code>web.xml
</code> and creates an empty one if necessary.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]