jenkins-bot has submitted this change and it was merged.

Change subject: Fix another regex compile error
......................................................................


Fix another regex compile error

This one is upstreamed as LUCENE-6054.

Change-Id: If80bc186d040f70e37d2b1b8faef8c9c254b4597
---
M src/main/java/org/apache/lucene/util/automaton/XOperations.java
M src/test/java/org/apache/lucene/util/automaton/TestRegExp.java
2 files changed, 16 insertions(+), 0 deletions(-)

Approvals:
  Chad: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/main/java/org/apache/lucene/util/automaton/XOperations.java 
b/src/main/java/org/apache/lucene/util/automaton/XOperations.java
index 8d5b42c..4f6f096 100644
--- a/src/main/java/org/apache/lucene/util/automaton/XOperations.java
+++ b/src/main/java/org/apache/lucene/util/automaton/XOperations.java
@@ -174,6 +174,10 @@
    * Complexity: linear in number of states.
    */
   static public XAutomaton repeat(XAutomaton a) {
+    if (a.getNumStates() == 0) {
+      // Repeating the empty automata will still only accept the empty 
automata.
+      return a;
+    }
     XAutomaton.Builder builder = new XAutomaton.Builder();
     builder.createState();
     builder.setAccept(0, true);
diff --git a/src/test/java/org/apache/lucene/util/automaton/TestRegExp.java 
b/src/test/java/org/apache/lucene/util/automaton/TestRegExp.java
index 8290e84..c84dd5c 100644
--- a/src/test/java/org/apache/lucene/util/automaton/TestRegExp.java
+++ b/src/test/java/org/apache/lucene/util/automaton/TestRegExp.java
@@ -49,4 +49,16 @@
                        assert(e.getMessage().contains(source));
                }
        }
+
+       public void testRepeatWithEmptyLanguage() throws Exception {
+          XAutomaton a = new XRegExp("#*").toAutomaton(1000);
+          // paranoia:
+          assertTrue(a.toString().length() > 0);
+          a = new XRegExp("#+").toAutomaton(1000);
+          assertTrue(a.toString().length() > 0);
+          a = new XRegExp("#{2,10}").toAutomaton(1000);
+          assertTrue(a.toString().length() > 0);
+          a = new XRegExp("#?").toAutomaton(1000);
+          assertTrue(a.toString().length() > 0);
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/171966
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If80bc186d040f70e37d2b1b8faef8c9c254b4597
Gerrit-PatchSet: 1
Gerrit-Project: search/extra
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: Chad <ch...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to