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

This commit is contained in:
Erick Erickson 2017-05-02 13:58:47 -07:00
parent 366a5d242e
commit 0be8e17832
3 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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;

View File

@ -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