DO NOT REPLY [Bug 9556] - Subgroup wrong when matching (.)(?=(.)) against "XY"?

[email protected]
Newsgroups gmane.comp.jakarta.oro.devel
Message-ID <[email protected]>
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9556>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9556

Subgroup wrong when matching (.)(?=(.)) against "XY"?





------- Additional Comments From [email protected]  2002-06-01 00:40 -------
Here's a patch that fixes the case you reported.  I don't think it
breaks anything else, but I can't be sure.  Any volunteers for those
unit tests we keep talking about?  At any rate, I don't want to apply
the patch until it has been well-tested.

Index: src/java/org/apache/oro/text/regex/Perl5MatchResult.java
===================================================================
RCS file:
/home/cvs/jakarta-oro/src/java/org/apache/oro/text/regex/Perl5MatchResult.java,v
retrieving revision 1.4
diff -u -r1.4 Perl5MatchResult.java
--- src/java/org/apache/oro/text/regex/Perl5MatchResult.java	17 May 2001 21:59:33 -0000	1.4
+++ src/java/org/apache/oro/text/regex/Perl5MatchResult.java	31 May 2002 16:21:15 -0000
@@ -125,7 +125,11 @@
    * @return The length of the match.
    */
   public int length(){
-    return _match.length();
+    int length;
+
+    length = (_endGroupOffset[0] - _beginGroupOffset[0]);
+
+    return (length > 0 ? length : 0);
   }
 
 
Index: src/java/org/apache/oro/text/regex/Perl5Matcher.java
===================================================================
RCS file:
/home/cvs/jakarta-oro/src/java/org/apache/oro/text/regex/Perl5Matcher.java,v
retrieving revision 1.18
diff -u -r1.18 Perl5Matcher.java
--- src/java/org/apache/oro/text/regex/Perl5Matcher.java	25 Jan 2002 09:32:28 -0000	1.18
+++ src/java/org/apache/oro/text/regex/Perl5Matcher.java	31 May 2002 16:21:16 -0000
@@ -241,7 +241,7 @@
   // Set the match result information.  Only call this if we successfully
   // matched.
   private void __setLastMatchResult() {
-    int offs;
+    int offs, maxEndOffs = 0;
 
     //endOffset+=dontTry;
 
@@ -251,10 +251,6 @@
     if(__endMatchOffsets[0] > __originalInput.length)
       throw new ArrayIndexOutOfBoundsException();
 
-    __lastMatchResult._match =
-      new String(__originalInput, __beginMatchOffsets[0],
-
	 __endMatchOffsets[0] - __beginMatchOffsets[0]);
-
     __lastMatchResult._matchBeginOffset = __beginMatchOffsets[0];
 
     while(__numParentheses >= 0) {
@@ -269,15 +265,21 @@
 
       offs = __endMatchOffsets[__numParentheses];
 
-      if(offs >= 0)
+      if(offs >= 0) {
 	__lastMatchResult._endGroupOffset[__numParentheses] =
 	  offs - __lastMatchResult._matchBeginOffset;
-      else
+
if(offs > maxEndOffs && offs <= __originalInput.length)
+
  maxEndOffs = offs;
+      } else
 	__lastMatchResult._endGroupOffset[__numParentheses] =
 	  OpCode._NULL_OFFSET;
 
       --__numParentheses;
     }
+
+    __lastMatchResult._match =
+      new String(__originalInput, __beginMatchOffsets[0],
+
	 maxEndOffs - __beginMatchOffsets[0]);
 
     // Free up for garbage collection
     __originalInput = null;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.