tang-hi opened a new pull request, #12277:
URL: https://github.com/apache/lucene/pull/12277

   ### Description
   ISSUE #12251 
   
   This pull request addresses two issues in the [RegExp.java 
code](https://github.com/apache/lucene/blob/a39885fdab93c4cbbcab8f3112c9783a05ca15a9/lucene/core/src/java/org/apache/lucene/util/automaton/RegExp.java#LL1088C3-L1111C4):
   
   1. It unifies the exception handling by ensuring that 
IllegalArgumentException is thrown when Integer.parseInt fails, such as in 
cases of overflow, as per the method signature.
   2. It adds a check for the correct order of the repetition range. 
Previously, the code would parse and accept invalid repetition ranges like 
"a{99,11}" that are not accepted by Java's Pattern. This update prevents such 
cases from being passed.
   
   Original Code
   ````
     final RegExp parseRepeatExp() throws IllegalArgumentException {
       RegExp e = parseComplExp();
       while (peek("?*+{")) {
         if (match('?')) e = makeOptional(flags, e);
         else if (match('*')) e = makeRepeat(flags, e);
         else if (match('+')) e = makeRepeat(flags, e, 1);
         else if (match('{')) {
           int start = pos;
           while (peek("0123456789")) next();
           if (start == pos) throw new IllegalArgumentException("integer 
expected at position " + pos);
           int n = Integer.parseInt(originalString.substring(start, pos));
           int m = -1;
           if (match(',')) {
             start = pos;
             while (peek("0123456789")) next();
             if (start != pos) m = 
Integer.parseInt(originalString.substring(start, pos));
           } else m = n;
           if (!match('}')) throw new IllegalArgumentException("expected '}' at 
position " + pos);
           if (m == -1) e = makeRepeat(flags, e, n);
           else e = makeRepeat(flags, e, n, m);
         }
       }
       return e;
     }
     ````
     
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to