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:20:46 UTC

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

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x a975385d5 -> 61c4dfb4a


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

(cherry picked from commit 0be8e17)


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

Branch: refs/heads/branch_6x
Commit: 61c4dfb4a424d1611d7de835fd474430c42abe89
Parents: a975385
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 14:20:26 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/61c4dfb4/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4eded78..74d46b3 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -221,6 +221,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/61c4dfb4/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 4a8161c..fa998d4 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
@@ -748,7 +748,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) {
@@ -761,9 +765,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/61c4dfb4/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