Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-10519: SolrCLI.atPath cannot handle children that begin with a slash.

Erick Erickson0be8e1783211
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 77366700a39..8f208311572 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -324,6 +324,8 @@ Other Changes
* SOLR-9386: Upgrade Zookeeper to 3.4.10. (Shawn Heisey, Steve Rowe)
+* SOLR-10519: SolrCLI.atPath cannot handle children that begin with a slash. (Erick Erickson)
+
================== 6.5.1 ==================
Bug Fixes
diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
index 7be76af6ed1..a6a40a098b2 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
@@ -747,7 +747,11 @@ public class SolrCLI {
}
/**
- * Helper function for reading an Object of unknown type from a JSON Object tree.
+ * Helper function for reading an Object of unknown type from a JSON Object tree.
+ *
+ * To find a path to a child that starts with a slash (e.g. queryHandler named /query)
+ * you must escape the slash. For instance /config/requestHandler/\/query/defaults/echoParams
+ * would get the echoParams value for the "/query" request handler.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static Object atPath(String jsonPath, Map<String,Object> json) {
@@ -760,9 +764,15 @@ public class SolrCLI {
Map<String,Object> parent = json;
Object result = null;
- String[] path = jsonPath.split("/");
+ String[] path = jsonPath.split("(?<![\\\\])/"); // Break on all slashes _not_ preceeded by a backslash
for (int p=1; p < path.length; p++) {
- Object child = parent.get(path[p]);
+ String part = path[p];
+
+ if (part.startsWith("\\")) {
+ part = part.substring(1);
+ }
+
+ Object child = parent.get(part);
if (child == null)
break;
diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
index 8c49f6b8ca4..5e98f054337 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
@@ -227,6 +227,14 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
assertNotNull(maxTimeFromConfig);
assertEquals(maxTime, maxTimeFromConfig);
+ // Just check that we can access paths with slashes in them both through an intermediate method and explicitly
+ // using atPath.
+ assertEquals("Should have been able to get a value from the /query request handler",
+ "explicit", SolrCLI.asString("/config/requestHandler/\\/query/defaults/echoParams", configJson));
+
+ assertEquals("Should have been able to get a value from the /query request handler",
+ "explicit", SolrCLI.atPath("/config/requestHandler/\\/query/defaults/echoParams", configJson));
+
log.info("live_nodes_count : " + cloudClient.getZkStateReader().getClusterState().getLiveNodes());
// Since it takes some time for this command to complete we need to make sure all the reloads for