mirror of https://github.com/apache/lucene.git
catch another case where CP can silently corrupt
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1456500 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
55cb4b443f
commit
412a233f5b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue