Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/org/apache/sling/api/uri/SlingUriBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ public static SlingUriBuilder createFrom(@NotNull URI uri, @Nullable ResourceRes
String path = uri.getRawPath();
boolean pathExists = isNotBlank(path);
String uriQuery = uri.getRawQuery();
boolean schemeSpecificRelevant = !pathExists && uriQuery == null;
String uriHost = uri.getHost();
if (FILE_SCHEME.equals(uri.getScheme()) && uriHost == null) {
uriHost = ""; // ensure three slashes in file URIs without host
Expand All @@ -240,7 +239,7 @@ public static SlingUriBuilder createFrom(@NotNull URI uri, @Nullable ResourceRes
.setPath(pathExists ? path : null)
.setQuery(uriQuery)
.setFragment(uri.getRawFragment())
.setSchemeSpecificPart(schemeSpecificRelevant ? uri.getRawSchemeSpecificPart() : null);
.setSchemeSpecificPart(uri.isOpaque() ? uri.getRawSchemeSpecificPart() : null);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/apache/sling/api/uri/SlingUriTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,21 @@ public void testGetSuffixResource() {
assertNull("Suffix resource is null if suffix is null", slingUriNoSuffix.getSuffixResource());
}

@Test
public void testWithSchemeAndHostWithoutQueryAndPath() {
SlingUri testUri =
SlingUriBuilder.parse("https://sling.apache.org", null).build();
assertEquals("https://sling.apache.org", testUri.toUri().toASCIIString());
}

@Test
public void testHostWithoutSchemeAndQueryAndPath() {
SlingUri testUri = SlingUriBuilder.parse("sling.apache.org", null).build();
assertEquals("sling.apache.org", testUri.toUri().toASCIIString());
testUri = SlingUriBuilder.parse("//sling.apache.org", null).build();
assertEquals("//sling.apache.org", testUri.toUri().toASCIIString());
}

// -- helper methods
public static void testUri(
String testUri,
Expand Down