Skip to content

Commit

Permalink
webdav: fix infinite recursion in Requests.stripToPath
Browse files Browse the repository at this point in the history
fixes commit 830a8a1

Result:
Fixes unreleased regression

Acked-by: Paul Millar
Acked-by: Lea Morschel
Target: master
Require-book: no
Require-notes: no
(cherry picked from commit f49389b)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  • Loading branch information
kofemann authored and mksahakyan committed Nov 7, 2023
1 parent 99d2444 commit 4632708
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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();
}
}
Expand Up @@ -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"));
}
}

0 comments on commit 4632708

Please sign in to comment.