Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-9016: Fix SolrIdentifierValidator to not accept empty identifiers

Shai Erera9166647918d2
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 101cdfd230d..4baea2cd1da 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -154,6 +154,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";
}
-}
-
+}