This is an automated email from the ASF dual-hosted git repository.
janhoy pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_10x by this push:
new 83b4807430b SOLR-18282 Improve ZookeeperInfoHandler path normalization
83b4807430b is described below
commit 83b4807430b7b7fb08ffe5d4d2a563300e5b1a91
Author: Jan Høydahl <[email protected]>
AuthorDate: Sun Jun 7 01:33:40 2026 +0200
SOLR-18282 Improve ZookeeperInfoHandler path normalization
(cherry picked from commit 449c598f46c4569f337ce2cbc33f6c8e478fc144)
---
.../solr/handler/admin/ZookeeperInfoHandler.java | 39 ++++++++--------------
.../handler/admin/ZookeeperInfoHandlerTest.java | 12 +++++++
2 files changed, 25 insertions(+), 26 deletions(-)
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java
b/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java
index 967c153071f..71c5efc3584 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java
@@ -73,6 +73,7 @@ import org.slf4j.LoggerFactory;
*/
public final class ZookeeperInfoHandler extends RequestHandlerBase {
private static final String PARAM_DETAIL = "detail";
+ private static final String PARAM_DUMP = "dump";
private final CoreContainer cores;
private static final Logger log =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -99,8 +100,9 @@ public final class ZookeeperInfoHandler extends
RequestHandlerBase {
public Name getPermissionName(AuthorizationContext request) {
var params = request.getParams();
String path = normalizePath(params.get(PATH, ""));
- String detail = params.get(PARAM_DETAIL, "false");
- if ("/security.json".equalsIgnoreCase(path) &&
"true".equalsIgnoreCase(detail)) {
+ boolean returnsContent =
+ params.getBool(PARAM_DETAIL, false) || params.getBool(PARAM_DUMP,
false);
+ if ("/security.json".equalsIgnoreCase(path) && returnsContent) {
return Name.SECURITY_READ_PERM;
} else {
return Name.ZK_READ_PERM;
@@ -413,7 +415,7 @@ public final class ZookeeperInfoHandler extends
RequestHandlerBase {
// Extract display options (applicable to graph view)
boolean detail = params.getBool(PARAM_DETAIL, false);
- boolean dump = params.getBool("dump", false);
+ boolean dump = params.getBool(PARAM_DUMP, false);
// Create response builder for paginated collections
return new ZkGraphResponseBuilder(
@@ -431,14 +433,9 @@ public final class ZookeeperInfoHandler extends
RequestHandlerBase {
* @return JSON string representing the ZooKeeper path data
*/
private ZkBaseResponseBuilder handlePathViewRequest(SolrParams params) {
- // Extract path parameter
- String path = params.get(PATH);
-
- // Extract display options
+ String path = normalizePath(params.get(PATH));
boolean detail = params.getBool(PARAM_DETAIL, false);
- boolean dump = params.getBool("dump", false);
-
- // Create response builder for specific path
+ boolean dump = params.getBool(PARAM_DUMP, false);
return new ZkPathResponseBuilder(cores.getZkController(), path, detail,
dump);
}
@@ -504,8 +501,12 @@ public final class ZookeeperInfoHandler extends
RequestHandlerBase {
}
@SuppressForbidden(reason = "JDK String class doesn't offer a stripEnd
equivalent")
- private String normalizePath(String path) {
- return StringUtils.stripEnd(path, "/");
+ String normalizePath(String path) {
+ if (path == null) {
+ return "/";
+ }
+ String normalized = StringUtils.stripEnd(path.trim(), "/");
+ return normalized.isEmpty() ? "/" : normalized;
}
//
--------------------------------------------------------------------------------------
@@ -569,20 +570,6 @@ public final class ZookeeperInfoHandler extends
RequestHandlerBase {
return;
}
- // normalize path
- if (path == null) {
- path = "/";
- } else {
- path = path.trim();
- if (path.isEmpty()) {
- path = "/";
- }
- }
-
- if (path.endsWith("/") && path.length() > 1) {
- path = path.substring(0, path.length() - 1);
- }
-
int idx = path.lastIndexOf('/');
String parent = idx >= 0 ? path.substring(0, idx) : path;
if (parent.isEmpty()) {
diff --git
a/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperInfoHandlerTest.java
b/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperInfoHandlerTest.java
index 91bbaa18180..f0f10a2920f 100644
---
a/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperInfoHandlerTest.java
+++
b/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperInfoHandlerTest.java
@@ -235,6 +235,18 @@ public class ZookeeperInfoHandlerTest extends
SolrCloudTestCase {
assertTrue("Collection should have shards",
collectionState.containsKey("shards"));
}
+ @Test
+ public void testNormalizePath() {
+ ZookeeperInfoHandler handler =
+ new
ZookeeperInfoHandler(cluster.getJettySolrRunner(0).getCoreContainer());
+
+ assertEquals("/foo", handler.normalizePath(" /foo"));
+ assertEquals("/foo", handler.normalizePath("/foo "));
+ assertEquals("/foo", handler.normalizePath("/foo/"));
+ assertEquals("/", handler.normalizePath(null));
+ assertEquals("/", handler.normalizePath(" "));
+ }
+
@Test
public void testZkInfoHandlerForcesJsonResponse() throws Exception {
// Create a test collection