diff --git a/modules/dcache-webdav/src/main/java/org/dcache/webdav/Requests.java b/modules/dcache-webdav/src/main/java/org/dcache/webdav/Requests.java index b78ad9da39a..2a69e05d230 100644 --- a/modules/dcache-webdav/src/main/java/org/dcache/webdav/Requests.java +++ b/modules/dcache-webdav/src/main/java/org/dcache/webdav/Requests.java @@ -23,13 +23,13 @@ import com.google.common.base.Splitter; import com.google.common.collect.Multimaps; import com.google.common.net.MediaType; + import java.util.Comparator; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nullable; import java.net.URI; -import java.net.URL; import java.nio.file.Path; import java.util.Collection; @@ -169,7 +169,7 @@ private static float qValueOf(MediaType m) { * @return The path component of the URL. */ public static String stripToPath(String uri) { - return stripToPath(URI.create(uri).getPath()); + return stripToPath(URI.create(uri)); } /** @@ -178,7 +178,7 @@ public static String stripToPath(String uri) { * @param url The URL to extract path from. * @return The path component of the URL. */ - public static String stripToPath(URL url) { + public static String stripToPath(URI url) { return Path.of(url.getPath()).normalize().toString(); } } diff --git a/modules/dcache-webdav/src/test/java/org/dcache/webdav/RequestsTest.java b/modules/dcache-webdav/src/test/java/org/dcache/webdav/RequestsTest.java index 2d2ccdad41b..af6a1d1ec0d 100644 --- a/modules/dcache-webdav/src/test/java/org/dcache/webdav/RequestsTest.java +++ b/modules/dcache-webdav/src/test/java/org/dcache/webdav/RequestsTest.java @@ -112,24 +112,24 @@ public void shouldAcceptWithMatchingParameter() { @Test public void shouldReturnFilePathOfUrl() throws MalformedURLException { - var u = new URL("https://door.domain.foo/pnfs/domain.foo/path/to/file"); + var u = new URL("https://door.domain.foo/pnfs/domain.foo/path/to/file").toString(); assertThat(Requests.stripToPath(u), equalTo("/pnfs/domain.foo/path/to/file")); } @Test public void shouldReturnFilePathOfUrlWithPort() throws MalformedURLException { - var u = new URL("https://door.domain.foo:1234/pnfs/domain.foo/path/to/file?foo=bar"); + var u = new URL("https://door.domain.foo:1234/pnfs/domain.foo/path/to/file?foo=bar").toString(); assertThat(Requests.stripToPath(u), equalTo("/pnfs/domain.foo/path/to/file")); } @Test public void shouldReturnFilePathOfUrlWithPortAndExtraSlash() throws MalformedURLException { - var u = new URL("https://door.domain.foo:1234//pnfs/domain.foo//path/to/file"); + var u = new URL("https://door.domain.foo:1234//pnfs/domain.foo//path/to/file").toString(); assertThat(Requests.stripToPath(u), equalTo("/pnfs/domain.foo/path/to/file")); } @Test public void shouldReturnFilePathOfUrlWithQuery() throws MalformedURLException { - var u = new URL("https://door.domain.foo:1234/pnfs/domain.foo/path/to/file?foo=bar"); + var u = new URL("https://door.domain.foo:1234/pnfs/domain.foo/path/to/file?foo=bar").toString(); assertThat(Requests.stripToPath(u), equalTo("/pnfs/domain.foo/path/to/file")); } } \ No newline at end of file