You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2017/05/02 21:13:50 UTC

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

Repository: lucene-solr
Updated Branches:
  refs/heads/master 366a5d242 -> 0be8e1783


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


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0be8e178
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0be8e178
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0be8e178

Branch: refs/heads/master
Commit: 0be8e1783211c7972b63e974cf32cb8d94cd4a22
Parents: 366a5d2
Author: Erick Erickson <er...@apache.org>
Authored: Tue May 2 13:58:47 2017 -0700
Committer: Erick Erickson <er...@apache.org>
Committed: Tue May 2 13:58:47 2017 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                    |  2 ++
 .../core/src/java/org/apache/solr/util/SolrCLI.java | 16 +++++++++++++---
 .../org/apache/solr/cloud/SolrCloudExampleTest.java |  8 ++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0be8e178/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7736670..8f20831 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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0be8e178/solr/core/src/java/org/apache/solr/util/SolrCLI.java
----------------------------------------------------------------------
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 7be76af..a6a40a0 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;
       

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0be8e178/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
----------------------------------------------------------------------
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 8c49f6b..5e98f05 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