vgritsenko 2004/01/30 16:10:44
Modified: src/java/org/apache/regexp RE.java RETest.java
Log:
Fix exception happening when subst with RE.REPLACE_BACKREFERENCES is called but
there were no backreferences
specified (see bug #25985)
Revision Changes Path
1.17 +2 -2 jakarta-regexp/src/java/org/apache/regexp/RE.java
Index: RE.java
===================================================================
RCS file: /home/cvs/jakarta-regexp/src/java/org/apache/regexp/RE.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- RE.java 30 Jan 2004 14:47:04 -0000 1.16
+++ RE.java 31 Jan 2004 00:10:44 -0000 1.17
@@ -1742,7 +1742,7 @@
{
// Process backreferences
int lCurrentPosition = 0;
- int lLastPosition = 0;
+ int lLastPosition = -2;
int lLength = substitution.length();
boolean bAddedPrefix = false;
1.11 +22 -17 jakarta-regexp/src/java/org/apache/regexp/RETest.java
Index: RETest.java
===================================================================
RCS file: /home/cvs/jakarta-regexp/src/java/org/apache/regexp/RETest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- RETest.java 30 Jan 2004 14:47:04 -0000 1.10
+++ RETest.java 31 Jan 2004 00:10:44 -0000 1.11
@@ -399,19 +399,6 @@
showParens(r);
}
- // Test subst() with backreferences
- r = new RE("http://[\\.\\w\\-\\?/~_@&=%]+");
- String s = r.subst("visit us: http://www.apache.org!",
- "1234<a href=\"$0\">$0</a>", RE.REPLACE_BACKREFERENCES);
- assertEquals("Wrong subst() result", "visit us: 1234<a
href=\"http://www.apache.org\">http://www.apache.org</a>!", s);
-
- // Test subst() with backreferences without leading characters
- // before first backreference
- r = new RE("(.*?)=(.*)");
- s = r.subst("variable=value",
- "$1_test_$212", RE.REPLACE_BACKREFERENCES);
- assertEquals("Wrong subst() result", "variable_test_value12", s);
-
// Test MATCH_MULTILINE. Test for eol/bol symbols.
r = new RE("^abc$", RE.MATCH_MULTILINE);
if (!r.match("\nabc")) {
@@ -528,9 +515,27 @@
{
RE r = new RE("a*b");
String expected = "-foo-garply-wacky-";
- String s1 = r.subst("aaaabfooaaabgarplyaaabwackyb", "-");
- say("s = " + s1);
- assertEquals("Wrong result of substitution", expected, s1);
+ String actual = r.subst("aaaabfooaaabgarplyaaabwackyb", "-");
+ assertEquals("Wrong result of substitution in \"a*b\"", expected, actual);
+
+ // Test subst() with backreferences
+ r = new RE("http://[\\.\\w\\-\\?/~_@&=%]+");
+ actual = r.subst("visit us: http://www.apache.org!",
+ "1234<a href=\"$0\">$0</a>", RE.REPLACE_BACKREFERENCES);
+ assertEquals("Wrong subst() result", "visit us: 1234<a
href=\"http://www.apache.org\">http://www.apache.org</a>!", actual);
+
+ // Test subst() with backreferences without leading characters
+ // before first backreference
+ r = new RE("(.*?)=(.*)");
+ actual = r.subst("variable=value",
+ "$1_test_$212", RE.REPLACE_BACKREFERENCES);
+ assertEquals("Wrong subst() result", "variable_test_value12", actual);
+
+ // Test subst() with NO backreferences
+ r = new RE("^a$");
+ actual = r.subst("a",
+ "b", RE.REPLACE_BACKREFERENCES);
+ assertEquals("Wrong subst() result", "b", actual);
}
public void assertEquals(String message, String expected, String actual)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]