From d98301c21bcd321610d34b3e0fdb9021224da1a6 Mon Sep 17 00:00:00 2001 From: "Brouns, Robin" Date: Wed, 21 Jan 2026 11:02:47 +0100 Subject: [PATCH 1/2] SLING-13065 Add test cases for StringIndexOutOfBounds bug --- .../org/apache/sling/api/uri/SlingUriTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/apache/sling/api/uri/SlingUriTest.java b/src/test/java/org/apache/sling/api/uri/SlingUriTest.java index 9a60d458..2835072f 100644 --- a/src/test/java/org/apache/sling/api/uri/SlingUriTest.java +++ b/src/test/java/org/apache/sling/api/uri/SlingUriTest.java @@ -19,6 +19,7 @@ package org.apache.sling.api.uri; import java.net.URI; +import java.net.URISyntaxException; import java.util.List; import java.util.function.Consumer; @@ -1024,6 +1025,20 @@ public void testHostWithoutSchemeAndQueryAndPath() { assertEquals("//sling.apache.org", testUri.toUri().toASCIIString()); } + @Test + public void testWithSchemeAndMappedPathWithSlashAsLastCharacter() { + SlingUri testUri = SlingUriBuilder.parse("https://sling.apache.org/apidocs/sling12/", resolver) + .build(); + assertEquals("https://sling.apache.org/apidocs/sling12", testUri.toUri().toASCIIString()); + } + + @Test + public void testWithSchemeAndMappedPathWithSlashAsLastCharacterCreateFromUri() throws URISyntaxException { + URI input = new URI("https://sling.apache.org/apidocs/sling12/"); + SlingUri testUri = SlingUriBuilder.createFrom(input, resolver).build(); + assertEquals("https://sling.apache.org/apidocs/sling12", testUri.toUri().toASCIIString()); + } + // -- helper methods public static void testUri( String testUri, From d50e5bc4f6d61ea7c008d4e7ff7b4859fc3dd590 Mon Sep 17 00:00:00 2001 From: "Brouns, Robin" Date: Wed, 21 Jan 2026 11:17:54 +0100 Subject: [PATCH 2/2] SLING-13065 Don't try to further process the resource path, if there are no selectors or extension --- src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java b/src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java index 582b925a..27923d0c 100644 --- a/src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java +++ b/src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java @@ -445,7 +445,7 @@ public SlingUriBuilder rebaseResourcePath() { selectors.clear(); extension = null; suffix = null; - if (availableResourcePath.length() == path.length()) { + if (availableResourcePath.length() == path.length() || !path.contains(CHAR_DOT)) { resourcePath = availableResourcePath; } else { setPathWithDefinedResourcePosition(path, availableResourcePath.length());