Permalink
Browse files

fix empty string corner cases

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671497 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
mikemccand committed Apr 6, 2015
1 parent 1f6ae07 commit a56852e4abc78d97e053f11e1416349d10019b4a
@@ -233,25 +233,27 @@ public static Automaton makeBinaryInterval(BytesRef min, boolean minInclusive, B
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();
@@ -1125,6 +1125,8 @@ public void testMakeBinaryIntervalRandom() throws Exception {
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 void testMakeBinaryIntervalOpenBoth() throws Exception {
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));
}

0 comments on commit a56852e

Please sign in to comment.