[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] RFC: gnu.regexp fix to avoid unwanted PatternSyntaxExceptio
From: |
Ito Kazumitsu |
Subject: |
[cp-patches] RFC: gnu.regexp fix to avoid unwanted PatternSyntaxException |
Date: |
Thu, 05 Jan 2006 23:47:03 +0900 (JST) |
This fixes the bug #25616.
I have updated the mauve test
gnu/testlet/java/util/regex/Pattern/matches.java
for testing this fix.
ChangeLog:
2006-01-05 Ito Kazumitsu <address@hidden>
* gnu/regexp/RE.java(initialize): Allow repeat.empty.token.
* gnu/regexp/RETokenRepeated.java(match): Break the loop
when an empty string matched an empty token.
Index: classpath/gnu/regexp/RE.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/RE.java,v
retrieving revision 1.7
diff -u -r1.7 RE.java
--- classpath/gnu/regexp/RE.java 2 Jul 2005 20:32:15 -0000 1.7
+++ classpath/gnu/regexp/RE.java 5 Jan 2006 14:28:33 -0000
@@ -386,8 +386,10 @@
throw new
REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,newIndex);
if (currentToken instanceof RETokenWordBoundary || currentToken
instanceof RETokenWordBoundary)
throw new
REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,newIndex);
- if ((currentToken.getMinimumLength() == 0) && (minMax.second ==
Integer.MAX_VALUE))
- throw new
REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,newIndex);
+ // Allow repeat.empty.token
+ // if ((currentToken.getMinimumLength() == 0) && (minMax.second ==
Integer.MAX_VALUE)) {
+ // throw new
REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,newIndex);
+ // }
index = newIndex;
currentToken =
setRepeated(currentToken,minMax.first,minMax.second,index);
}
@@ -624,8 +626,10 @@
throw new
REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index);
if (currentToken instanceof RETokenWordBoundary || currentToken
instanceof RETokenWordBoundary)
throw new
REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index);
- if (currentToken.getMinimumLength() == 0)
- throw new
REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,index);
+ // Allow repeat.empty.token
+ // if (currentToken.getMinimumLength() == 0) {
+ // throw new
REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,index);
+ // }
currentToken = setRepeated(currentToken,0,Integer.MAX_VALUE,index);
}
@@ -648,8 +652,10 @@
}
else if (currentToken instanceof RETokenWordBoundary || currentToken
instanceof RETokenWordBoundary)
throw new
REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index);
- else if (currentToken.getMinimumLength() == 0)
- throw new
REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,index);
+ // Allow repeat.empty.token
+ // else if (currentToken.getMinimumLength() == 0) {
+ // throw new
REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,index);
+ // }
else
currentToken = setRepeated(currentToken,1,Integer.MAX_VALUE,index);
}
Index: classpath/gnu/regexp/RETokenRepeated.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/RETokenRepeated.java,v
retrieving revision 1.3
diff -u -r1.3 RETokenRepeated.java
--- classpath/gnu/regexp/RETokenRepeated.java 2 Jul 2005 20:32:15 -0000
1.3
+++ classpath/gnu/regexp/RETokenRepeated.java 5 Jan 2006 14:28:33 -0000
@@ -108,6 +108,7 @@
REMatch doables;
REMatch doablesLast;
REMatch recurrent;
+ int lastIndex = mymatch.index;
do {
// Check for stingy match for each possibility.
@@ -151,6 +152,14 @@
++numRepeats;
positions.addElement(newMatch);
+
+ // doables.index == lastIndex means an empty string
+ // was the longest that matched this token.
+ // We break here, otherwise we will fall into an endless loop.
+ if (doables.index == lastIndex && numRepeats >= min) {
+ break;
+ }
+ lastIndex = doables.index;
} while (numRepeats < max);
// If there aren't enough repeats, then fail
- [cp-patches] RFC: gnu.regexp fix to avoid unwanted PatternSyntaxException,
Ito Kazumitsu <=