lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1637451 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/util/automaton/Operations.java core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
Date Fri, 07 Nov 2014 21:24:52 GMT
Author: mikemccand
Date: Fri Nov  7 21:24:52 2014
New Revision: 1637451

URL: http://svn.apache.org/r1637451
Log:
LUCENE-6054: allow repeating the empty automaton

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1637451&r1=1637450&r2=1637451&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Fri Nov  7 21:24:52 2014
@@ -212,6 +212,9 @@ Bug Fixes
   now throws an exception instead of exhausting CPU/RAM.  (Nik
   Everett via Mike McCandless)
 
+* LUCENE-6054: Allow repeating the empty automaton (Nik Everett via
+  Mike McCandless)
+
 Documentation
 
 * LUCENE-5392: Add/improve analysis package documentation to reflect

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java?rev=1637451&r1=1637450&r2=1637451&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
Fri Nov  7 21:24:52 2014
@@ -29,6 +29,13 @@
 
 package org.apache.lucene.util.automaton;
 
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.BytesRefBuilder;
+import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.IntsRefBuilder;
+import org.apache.lucene.util.RamUsageEstimator;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
@@ -40,13 +47,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.BytesRefBuilder;
-import org.apache.lucene.util.IntsRef;
-import org.apache.lucene.util.IntsRefBuilder;
-import org.apache.lucene.util.RamUsageEstimator;
-
 /**
  * Automata operations.
  * 
@@ -174,6 +174,10 @@ final public class Operations {
    * Complexity: linear in number of states.
    */
   static public Automaton repeat(Automaton a) {
+    if (a.getNumStates() == 0) {
+      // Repeating the empty automata will still only accept the empty automata.
+      return a;
+    }
     Automaton.Builder builder = new Automaton.Builder();
     builder.createState();
     builder.setAccept(0, true);

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java?rev=1637451&r1=1637450&r2=1637451&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java
Fri Nov  7 21:24:52 2014
@@ -55,4 +55,16 @@ public class TestRegExp extends LuceneTe
     // paranoia:
     assertTrue(a.toString().length() > 0);
   }
+
+  public void testRepeatWithEmptyLanguage() throws Exception {
+    Automaton a = new RegExp("#*").toAutomaton(1000);
+    // paranoia:
+    assertTrue(a.toString().length() > 0);
+    a = new RegExp("#+").toAutomaton(1000);
+    assertTrue(a.toString().length() > 0);
+    a = new RegExp("#{2,10}").toAutomaton(1000);
+    assertTrue(a.toString().length() > 0);
+    a = new RegExp("#?").toAutomaton(1000);
+    assertTrue(a.toString().length() > 0);
+  }
 }



Mime
View raw message