HBASE-13050 Empty Namespace validation
Signed-off-by: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
This commit is contained in:
parent
f64d63d24e
commit
7b045d143a
|
@ -208,21 +208,21 @@ public final class TableName implements Comparable<TableName> {
|
|||
/**
|
||||
* Valid namespace characters are [a-zA-Z_0-9]
|
||||
*/
|
||||
public static void isLegalNamespaceName(byte[] namespaceName, int offset, int length) {
|
||||
for (int i = offset; i < length; i++) {
|
||||
public static void isLegalNamespaceName(final byte[] namespaceName,
|
||||
final int start,
|
||||
final int end) {
|
||||
if(end - start < 1) {
|
||||
throw new IllegalArgumentException("Namespace name must not be empty");
|
||||
}
|
||||
for (int i = start; i < end; i++) {
|
||||
if (Character.isLetterOrDigit(namespaceName[i])|| namespaceName[i] == '_') {
|
||||
continue;
|
||||
}
|
||||
throw new IllegalArgumentException("Illegal character <" + namespaceName[i] +
|
||||
"> at " + i + ". Namespaces can only contain " +
|
||||
"'alphanumeric characters': i.e. [a-zA-Z_0-9]: " + Bytes.toString(namespaceName,
|
||||
offset, length));
|
||||
start, end));
|
||||
}
|
||||
if(offset == length)
|
||||
throw new IllegalArgumentException("Illegal character <" + namespaceName[offset] +
|
||||
"> at " + offset + ". Namespaces can only contain " +
|
||||
"'alphanumeric characters': i.e. [a-zA-Z_0-9]: " + Bytes.toString(namespaceName,
|
||||
offset, length));
|
||||
}
|
||||
|
||||
public byte[] getName() {
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.util.Map;
|
|||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
@ -53,8 +52,8 @@ public class TestTableName extends TestWatcher {
|
|||
public TableName getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
String emptyTableNames[] ={"", " "};
|
||||
|
||||
String emptyNames[] ={"", " "};
|
||||
String invalidNamespace[] = {":a", "%:a"};
|
||||
String legalTableNames[] = { "foo", "with-dash_under.dot", "_under_start_ok",
|
||||
"with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02"
|
||||
|
@ -73,9 +72,17 @@ public class TestTableName extends TestWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEmptyNamespaceName() {
|
||||
for (String nn : emptyNames) {
|
||||
TableName.isLegalNamespaceName(Bytes.toBytes(nn));
|
||||
fail("invalid Namespace name " + nn + " should have failed with IllegalArgumentException");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testEmptyTableName() {
|
||||
for (String tn : emptyTableNames) {
|
||||
for (String tn : emptyNames) {
|
||||
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
|
||||
fail("invalid tablename " + tn + " should have failed with IllegalArgumentException");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue