From 95fcd5d230d33c1a654ee9023401a6a028c2cf1d Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Fri, 3 Nov 2023 12:44:38 +0100 Subject: [PATCH] webdav: fix infinite recursion in Requests.stripToPath fixes commit 830a8a1469 Result: Fixes unreleased regression Acked-by: Paul Millar Acked-by: Lea Morschel Target: master Require-book: no Require-notes: no (cherry picked from commit f49389bb914559355388e00570d4865e5b5df728) Signed-off-by: Tigran Mkrtchyan --- .../src/main/java/org/dcache/webdav/Requests.java | 6 +++--- .../src/test/java/org/dcache/webdav/RequestsTest.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) 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