This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch 1.x
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
The following commit(s) were added to refs/heads/1.x by this push:
new 9857e72d SLING-13301: test vanity path syntax variants (backport to
1.x) (#233)
9857e72d is described below
commit 9857e72def741991039a8b623d09f08ebc8d0216
Author: Julian Reschke <[email protected]>
AuthorDate: Tue Aug 18 14:01:15 2026 +0200
SLING-13301: test vanity path syntax variants (backport to 1.x) (#233)
---
.../impl/mapping/VanityPathMapEntriesTest.java | 60 ++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git
a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java
b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java
index 05706e03..87298f52 100644
---
a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java
+++
b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java
@@ -267,6 +267,66 @@ public class VanityPathMapEntriesTest extends
AbstractMappingMapEntriesTest {
assertNotNull(vanityMap.get("/" + containerName + "/" + oneMore));
}
+ // see https://issues.apache.org/jira/browse/SLING-13301
+ @Test
+ public void test_syntax_variants() {
+ // absolute path
+ assertPathResolvesTo("/x", "/x");
+ // relative path
+ assertPathResolvesTo("x", "/x");
+ // multi-segment absolute path
+ assertPathResolvesTo("/x/y", "/x/y");
+ // multi-segment relative path
+ assertPathResolvesTo("x/y", "/x/y");
+ // multi-segment absolute path starting with "//"
+ assertPathResolvesTo("//x//y", "//x//y");
+ // multi-segment absolute path starting with "/.."
+ assertPathResolvesTo("/../x", "/../x");
+ // blank path
+ assertPathResolvesTo(" ", null);
+ // empty path
+ assertPathResolvesTo("", null);
+ }
+
+ private void assertPathResolvesTo(String vanityPath, String expectedPath) {
+
+ String path = "/foo/bar";
+
+ prepareMapEntriesForSingleVanityPath(path, vanityPath);
+
+ initializeVanityPaths();
+
+ Map<String, List<String>> vanityMap =
mapEntries.getVanityPathMappings();
+
+ assertNotNull("vm should not be null", vanityMap);
+ if (expectedPath == null) {
+ assertEquals("size of vm should be 0", 0, vanityMap.size());
+ } else {
+ assertEquals("size of vm should be 1", 1, vanityMap.size());
+ assertNotNull("vp should be present in vm, got " + vanityMap,
vanityMap.get(path));
+ assertEquals(expectedPath, vanityMap.get(path).get(0));
+ }
+ }
+
+ private void prepareMapEntriesForSingleVanityPath(String node, String
vanityPath) {
+
+ Resource parent = createMockedResource(ResourceUtil.getParent(node));
+
+ Resource vanity = createMockedResource(node);
+ when(vanity.getParent()).thenReturn(parent);
+
when(vanity.getValueMap()).thenReturn(buildValueMap(VanityPathHandler.PROP_VANITY_PATH,
vanityPath));
+
+ when(resourceResolver.findResources(anyString(), eq("JCR-SQL2")))
+ .thenAnswer((Answer<Iterator<Resource>>) invocation -> {
+ String query = invocation.getArguments()[0].toString();
+ if (matchesPagedQuery(query)) {
+ return List.of(vanity).iterator();
+ } else {
+ return Collections.emptyIterator();
+ }
+ });
+ }
+
// see SLING-12620
@Test
public void test_simple_vanity_path_support_with_null_parent() {