Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

catch another case where CP can silently corrupt

Michael McCandless412a233f5bb6
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java
index 33f7400c1bd..5635397ca1c 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java
@@ -121,10 +121,14 @@ public class CategoryPath implements Comparable<CategoryPath> {
return length - other.length;
}
+ private void hasDelimiter(String offender, char delimiter) {
+ throw new IllegalArgumentException("delimiter character '" + delimiter + "' (U+" + Integer.toHexString(delimiter) + ") appears in path component \"" + offender + "\"");
+ }
+
private void noDelimiter(char[] buf, int offset, int len, char delimiter) {
for(int idx=0;idx<len;idx++) {
if (buf[offset+idx] == delimiter) {
- throw new IllegalArgumentException("delimiter character U+" + Integer.toHexString(delimiter) + " appears in path");
+ hasDelimiter(new String(buf, offset, len), delimiter);
}
}
}
@@ -237,6 +241,9 @@ public class CategoryPath implements Comparable<CategoryPath> {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
+ if (components[i].indexOf(delimiter) != -1) {
+ hasDelimiter(components[i], delimiter);
+ }
sb.append(components[i]).append(delimiter);
}
sb.setLength(sb.length() - 1); // remove last delimiter
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestCategoryPath.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestCategoryPath.java
index ef09ff70f66..8091c6ac4b3 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestCategoryPath.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestCategoryPath.java
@@ -216,5 +216,63 @@ public class TestCategoryPath extends FacetTestCase {
assertNotNull(new CategoryPath("test/", '/'));
}
+
+ @Test
+ public void testInvalidDelimChar() throws Exception {
+ // Make sure CategoryPath doesn't silently corrupt:
+ char[] buf = new char[100];
+ CategoryPath cp = new CategoryPath("foo/bar");
+ try {
+ cp.toString();
+ fail("expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ try {
+ cp.copyFullPath(buf, 0, '/');
+ fail("expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ cp = new CategoryPath("abc", "foo/bar");
+ try {
+ cp.toString();
+ fail("expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ try {
+ cp.copyFullPath(buf, 0, '/');
+ fail("expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ cp = new CategoryPath("foo:bar");
+ try {
+ cp.toString(':');
+ fail("expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ try {
+ cp.copyFullPath(buf, 0, ':');
+ fail("expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ cp = new CategoryPath("abc", "foo:bar");
+ try {
+ cp.toString(':');
+ fail("expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ try {
+ cp.copyFullPath(buf, 0, ':');
+ fail("expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ }
}