fix empty string corner cases

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671497 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-04-06 09:03:35 +00:00
parent bb29c9cd2a
commit 86fe84c1ee
2 changed files with 13 additions and 10 deletions

View File

@ -233,25 +233,27 @@ final public class Automata {
throw new IllegalArgumentException("maxInclusive must be true when max is null (open ended)");
}
if (min != null && min.length == 0 && minInclusive == true) {
// Silly empty string corner case:
min = null;
}
if (min == null) {
if (max == null) {
// Accepts all terms:
return makeAnyBinary();
}
min = new BytesRef();
minInclusive = true;
}
// Empty string corner case:
if (max != null && maxInclusive == false && max.length == 1 && max.bytes[max.offset] == 0) {
max = new BytesRef();
maxInclusive = true;
}
int cmp;
if (max != null) {
cmp = min.compareTo(max);
} else {
cmp = -1;
if (min.length == 0 && minInclusive) {
return makeAnyBinary();
}
}
if (cmp == 0) {
if (minInclusive == false || maxInclusive == false) {
return makeEmpty();

View File

@ -1125,6 +1125,8 @@ public class TestAutomaton extends LuceneTestCase {
System.out.println("Original was not minimal:");
System.out.println("Original:\n" + a.toDot());
System.out.println("Minimized:\n" + minA.toDot());
System.out.println("minTerm=" + minTerm + " minInclusive=" + minInclusive);
System.out.println("maxTerm=" + maxTerm + " maxInclusive=" + maxInclusive);
fail("auotmaton was not minimal");
}
@ -1233,7 +1235,6 @@ public class TestAutomaton extends LuceneTestCase {
public void testAcceptAllEmptyStringMin() throws Exception {
Automaton a = Automata.makeBinaryInterval(new BytesRef(), true, null, true);
System.out.println("HERE: " + a.toDot());
assertTrue(Operations.sameLanguage(Automata.makeAnyBinary(), a));
}