diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 4328c8dafbc..56a5f3b3e83 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -116,6 +116,8 @@ Bug Fixes * SOLR-9029: fix rare ZkStateReader visibility race during collection state format update (Scott Blum, hossman) +* SOLR-9016: Fix SolrIdentifierValidator to not allow empty identifiers. (Shai Erera) + Optimizations ---------------------- * SOLR-8722: Don't force a full ZkStateReader refresh on every Overseer operation. diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/util/SolrIdentifierValidator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/util/SolrIdentifierValidator.java index 9473a2806b6..d23b8bbf93d 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/util/SolrIdentifierValidator.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/util/SolrIdentifierValidator.java @@ -28,7 +28,7 @@ import org.apache.solr.common.SolrException; * Identifiers are allowed to contain underscores, periods, hyphens, and alphanumeric characters. */ public class SolrIdentifierValidator { - final static Pattern identifierPattern = Pattern.compile("^(?!\\-)[\\._A-Za-z0-9\\-]*$"); + final static Pattern identifierPattern = Pattern.compile("^(?!\\-)[\\._A-Za-z0-9\\-]+$"); public enum IdentifierType { SHARD, COLLECTION, CORE, ALIAS @@ -64,11 +64,9 @@ public class SolrIdentifierValidator { } public static String getIdentifierMessage(IdentifierType identifierType, String name) { - return "Invalid " + identifierType.toString().toLowerCase(Locale.ROOT) + ": " + name + ". " - + identifierType.toString().toLowerCase(Locale.ROOT) - + " names must consist entirely of periods, underscores, hyphens, and alphanumerics"; - + String typeStr = identifierType.toString().toLowerCase(Locale.ROOT); + return "Invalid " + typeStr + ": [" + name + "]. " + typeStr + " names must consist entirely of periods, " + + "underscores, hyphens, and alphanumerics as well not start with a hyphen"; } + } - -