You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2022/02/18 06:33:19 UTC
[GitHub] [sling-org-apache-sling-resourceresolver] humbledev123 commented on a change in pull request #50: SLING-10844: ResourceMapper.getMapping() returns null for empty path
humbledev123 commented on a change in pull request #50:
URL: https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/50#discussion_r809710061
##########
File path: src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
##########
@@ -72,7 +72,7 @@ public String getMapping(String resourcePath, HttpServletRequest request) {
Collection<String> mappings = getAllMappings(resourcePath, request);
if ( mappings.isEmpty() )
- return null;
+ return "";
Review comment:
Finding an appropriate mappings relies on having non-empty mappedPath or non-null nonDecoratedResource but in case if mappedPath is empty and nonDecoratedResource is null (it could be possible based on doc [0]) then there could be no possible mapping and the result would be empty. Besides I cold not think of any possible mapping which ought to be returned in such case, any thoughts ?
[0]: https://github.com/apache/sling-org-apache-sling-resourceresolver/blob/deb25ba47cf563e5bc52978eef36e80d735a067c/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java#L718
##########
File path: src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
##########
@@ -355,6 +358,31 @@ public void mapNestedAliasTarget() {
.allMappingsWithRequest("/app/alias-parent/alias-child", "/app/alias-parent/child", "/app/parent/alias-child")
.verify(resolver, req);
}
+
+ /**
+ * Validates that mappings for an empty path
+ *
+ * @throws LoginException
+ */
+ @Test
+ public void mapEmptyPathWithNonExistingResource() {
+ MapEntriesHandler mapEntriesHandler = mock(MapEntriesHandler.class);
+ when(mapEntriesHandler.getVanityPathMappings()).thenReturn(Collections.emptyMap());
+
+ ResourceResolverImpl resolver = mock(ResourceResolverImpl.class);
+ when(resolver.resolveInternal(any(), any())).thenReturn(null);
+ when(resolver.getResource("")).thenReturn(this.resolver.getResource(""));
+ when(resolver.adaptTo(ResourceMapper.class)).thenReturn(new ResourceMapperImpl(resolver, mock(ResourceDecoratorTracker.class),
+ mapEntriesHandler, mock(Object.class)));
+
+ ExpectedMappings.nonExistingResource("")
+ .singleMapping("")
+ .singleMappingWithRequest("")
+ .allMappings("")
+ .allMappingsWithRequest("")
+ .testingEmptyPathWithNonExistingResource(true)
Review comment:
This is for the case where resource is non-existing with empty path.
##########
File path: src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
##########
@@ -355,6 +358,31 @@ public void mapNestedAliasTarget() {
.allMappingsWithRequest("/app/alias-parent/alias-child", "/app/alias-parent/child", "/app/parent/alias-child")
.verify(resolver, req);
}
+
+ /**
+ * Validates that mappings for an empty path
+ *
+ * @throws LoginException
+ */
+ @Test
+ public void mapEmptyPathWithNonExistingResource() {
+ MapEntriesHandler mapEntriesHandler = mock(MapEntriesHandler.class);
+ when(mapEntriesHandler.getVanityPathMappings()).thenReturn(Collections.emptyMap());
+
+ ResourceResolverImpl resolver = mock(ResourceResolverImpl.class);
+ when(resolver.resolveInternal(any(), any())).thenReturn(null);
Review comment:
Apparently root path is not empty this was done to replicate the scenario which was observed in bug where path is empty and then resolveInternal ought to return null.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org