Skip to content
Snippets Groups Projects
Commit 8d95f2b9 authored by felmer's avatar felmer
Browse files

bug fixed: File names with spaces

SVN: 24317
parent 5b785315
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,6 @@ import java.lang.reflect.InvocationTargetException; ...@@ -21,7 +21,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
...@@ -49,6 +48,8 @@ import ch.systemsx.cisd.openbis.generic.shared.util.Key; ...@@ -49,6 +48,8 @@ import ch.systemsx.cisd.openbis.generic.shared.util.Key;
*/ */
public class DSSFileSystemView implements FileSystemView public class DSSFileSystemView implements FileSystemView
{ {
private static final String SPACE_ESCAPE = "__SPACE__";
private static final Set<String> METHOD_NAMES = new HashSet<String>(Arrays.asList( private static final Set<String> METHOD_NAMES = new HashSet<String>(Arrays.asList(
"tryToGetExperiment", "listDataSetsByExperimentID")); "tryToGetExperiment", "listDataSetsByExperimentID"));
...@@ -175,14 +176,15 @@ public class DSSFileSystemView implements FileSystemView ...@@ -175,14 +176,15 @@ public class DSSFileSystemView implements FileSystemView
try try
{ {
URI uri = new URI(fullPath); URI uri = new URI(fullPath.replaceAll(" ", SPACE_ESCAPE));
String normalizedPath = uri.normalize().toString(); String normalizedPath = uri.normalize().toString();
// remove trailing slashes // remove trailing slashes
normalizedPath = normalizedPath.replaceAll("/*$", ""); normalizedPath = normalizedPath.replaceAll("/*$", "");
// replace multiple adjacent slashes with a single slash // replace multiple adjacent slashes with a single slash
normalizedPath = normalizedPath.replaceAll("/+", "/"); normalizedPath = normalizedPath.replaceAll("/+", "/");
normalizedPath = normalizedPath.replaceAll(SPACE_ESCAPE, " ");
return StringUtils.isBlank(normalizedPath) ? FtpConstants.ROOT_DIRECTORY : normalizedPath; return StringUtils.isBlank(normalizedPath) ? FtpConstants.ROOT_DIRECTORY : normalizedPath;
} catch (URISyntaxException ex) } catch (Exception ex)
{ {
throw new FtpException("Cannot parse path " + fullPath, ex); throw new FtpException("Cannot parse path " + fullPath, ex);
} }
......
...@@ -84,11 +84,11 @@ public class DSSFileSystemViewTest extends AssertJUnit ...@@ -84,11 +84,11 @@ public class DSSFileSystemViewTest extends AssertJUnit
@Test @Test
public void testGetFile() throws FtpException public void testGetFile() throws FtpException
{ {
prepareTryResolve("/abc/ghi/jkl"); prepareTryResolve("/abc/g h_i/j k l");
FtpFile file = view.getFile("abc/def/../ghi//jkl//"); FtpFile file = view.getFile("abc/def/../g h_i//j k l//");
assertEquals("/abc/ghi/jkl", file.getAbsolutePath()); assertEquals("/abc/g h_i/j k l", file.getAbsolutePath());
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment