Repository: incubator-blur Updated Branches: refs/heads/apache-blur-0.2 d9e844c60 -> 76bdd4f59
Changing the rowid, recordid, family and column name validator from a regex to a hand coded method. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/2286f252 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/2286f252 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/2286f252 Branch: refs/heads/apache-blur-0.2 Commit: 2286f2523c5a3d02546610ba4babe06451d18570 Parents: 78a2409 Author: Aaron McCurry <[email protected]> Authored: Tue Jun 17 10:21:11 2014 -0400 Committer: Aaron McCurry <[email protected]> Committed: Tue Jun 17 10:21:11 2014 -0400 ---------------------------------------------------------------------- .../java/org/apache/blur/utils/BlurUtil.java | 41 +++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2286f252/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java index a6eda0f..02e6f63 100644 --- a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java +++ b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java @@ -59,7 +59,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLongArray; -import java.util.regex.Pattern; import org.apache.blur.BlurConfiguration; import org.apache.blur.index.ExitableReader.ExitableFilterAtomicReader; @@ -152,7 +151,6 @@ public class BlurUtil { private static final Class<?>[] EMPTY_PARAMETER_TYPES = new Class[] {}; private static final Log LOG = LogFactory.getLog(BlurUtil.class); private static final String UNKNOWN = "UNKNOWN"; - private static Pattern validator = Pattern.compile("^[a-zA-Z0-9\\_\\-]+$"); public static final Comparator<? super PeekableIterator<BlurResult, BlurException>> HITS_PEEKABLE_ITERATOR_COMPARATOR = new BlurResultPeekableIteratorComparator(); public static final Comparator<? super BlurResult> HITS_COMPARATOR = new BlurResultComparator(); @@ -1124,28 +1122,59 @@ public class BlurUtil { } public static void validateRowIdAndRecord(String rowId, Record record) { - if (!validator.matcher(record.family).matches()) { + if (!validate(record.family)) { throw new IllegalArgumentException("Invalid column family name [ " + record.family + " ]. It should contain only this pattern [A-Za-z0-9_-]"); } for (Column column : record.getColumns()) { - if (!validator.matcher(column.name).matches()) { + if (!validate(column.name)) { throw new IllegalArgumentException("Invalid column name [ " + column.name + " ]. It should contain only this pattern [A-Za-z0-9_-]"); } } } + public static boolean validate(String s) { + int length = s.length(); + for (int i = 0; i < length; i++) { + char c = s.charAt(i); + if (!validate(c)) { + return false; + } + } + return true; + } + + private static boolean validate(char c) { + if (c >= 'a' && c <= 'z') { + return true; + } + if (c >= 'A' && c <= 'Z') { + return true; + } + if (c >= '0' && c <= '9') { + return true; + } + switch (c) { + case '_': + return true; + case '-': + return true; + default: + return false; + } + } + public static void validateTableName(String tableName) { - if (!validator.matcher(tableName).matches()) { + if (!validate(tableName)) { throw new IllegalArgumentException("Invalid table name [ " + tableName + " ]. It should contain only this pattern [A-Za-z0-9_-]"); } } public static void validateShardName(String shardName) { - if (!validator.matcher(shardName).matches()) { + if (!validate(shardName)) { throw new IllegalArgumentException("Invalid shard name [ " + shardName + " ]. It should contain only this pattern [A-Za-z0-9_-]"); }
