This is an automated email from the ASF dual-hosted git repository. randgalt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/curator.git
commit 0128b96f4bc1766dc1fc37c70b0d98e72e50405f Author: Ryan Ruel <[email protected]> AuthorDate: Wed Aug 4 15:20:18 2021 -0400 Modified ZPathImpl's "isParameter()" method to properly check for parameters strings (values inside of a pair parameter delimiters). This corrects issues with checking for path resolution status in certain cases. Modified ZPathImpl's "resolved()" method to allow for substituted parameters to have leading path separators ("/"). This is useful in the case where a parameter is used for the first node element in the path, eliminating the need for the user to worry about the leading "/". Added an additional unit test case for the leading "/" changes, and fixed bugs in the basic test cases that were accepting the wrong resolved state of tested ZPaths. All unit tests for curator pass. --- .../main/java/org/apache/curator/x/async/modeled/ZPath.java | 7 +++++-- .../apache/curator/x/async/modeled/details/ZPathImpl.java | 7 +++++-- .../java/org/apache/curator/x/async/modeled/TestZPath.java | 13 ++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java index 70ac536..e15a6bc 100644 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java @@ -31,6 +31,9 @@ import static org.apache.curator.utils.ZKPaths.PATH_SEPARATOR; */ public interface ZPath extends Resolvable { + String PARAMETER_OPENING_DELIMITER = "{"; + String PARAMETER_CLOSING_DELIMITER = "}"; + /** * The root path: "/" */ @@ -52,7 +55,7 @@ public interface ZPath extends Resolvable */ static String parameter(String name) { - return PATH_SEPARATOR + "{" + name + "}"; + return PATH_SEPARATOR + PARAMETER_OPENING_DELIMITER + name + PARAMETER_CLOSING_DELIMITER; } /** @@ -241,7 +244,7 @@ public interface ZPath extends Resolvable boolean isRoot(); /** - * Return true if this path is fully resolved (i.e. has no unresoled parameters) + * Return true if this path is fully resolved (i.e. has no unresolved parameters) * * @return true/false */ diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java index fff742e..b04c4b4 100644 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java @@ -210,7 +210,9 @@ public class ZPathImpl implements ZPath .map(name -> { if ( isParameter(name) && iterator.hasNext() ) { - return NodeName.nameFrom(iterator.next()); + // Eliminate any leading path separator from substituted parameters, as ZPathImpl() will + // add in all required path separators as part of it's build operation. + return NodeName.nameFrom(iterator.next()).replaceAll(String.format("^%s+", PATH_SEPARATOR), ""); } return name; }) @@ -226,7 +228,8 @@ public class ZPathImpl implements ZPath private static boolean isParameter(String name) { - return (name.length() > 1) && name.startsWith(PATH_SEPARATOR); + return name.matches(String.format(".*\\%s.*\\%s", PARAMETER_OPENING_DELIMITER, + PARAMETER_CLOSING_DELIMITER)); } private ZPathImpl(List<String> nodes, String child) diff --git a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java index e35354c..c1d4697 100644 --- a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java +++ b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java @@ -57,11 +57,11 @@ public class TestZPath assertFalse(path.startsWith(ZPath.root.child("two"))); ZPath checkIdLike = ZPath.parse("/one/{two}/three"); - assertTrue(checkIdLike.isResolved()); + assertFalse(checkIdLike.isResolved()); checkIdLike = ZPath.parse("/one/" + ZPath.parameter() + "/three"); - assertTrue(checkIdLike.isResolved()); + assertFalse(checkIdLike.isResolved()); checkIdLike = ZPath.parse("/one/" + ZPath.parameter("others") + "/three"); - assertTrue(checkIdLike.isResolved()); + assertFalse(checkIdLike.isResolved()); } @Test @@ -71,6 +71,13 @@ public class TestZPath assertEquals(ZPath.parse("/one/two/three"), ZPath.root.child("one").child("two").child("three")); assertEquals(ZPath.parse("/one/two/three"), ZPath.from("one", "two", "three")); assertEquals(ZPath.parseWithIds("/one/{id}/two/{id}"), ZPath.from("one", parameter(), "two", parameter())); + + final ZPath rootPath = ZPath.parse("/root"); + ZPath path = ZPath.parseWithIds("{root}/one/{id}/two/{id}"); + assertFalse(path.isResolved()); + path = path.resolved(rootPath.toString(), "foo", "bar"); + assertEquals(ZPath.from("root", "one", "foo", "two", "bar").toString(), path.toString()); + assertTrue(path.isResolved()); } @Test
