Skip to content
Snippets Groups Projects
Commit f083a0aa authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Modified getVosPath method to correctly parsing encoded chars (e.g. %20)

parent c40d5a53
Branches
Tags
No related merge requests found
Pipeline #7980 passed
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
*/ */
package it.inaf.oats.vospace.datamodel; package it.inaf.oats.vospace.datamodel;
import java.net.URI;
import java.net.URISyntaxException;
import net.ivoa.xml.vospace.v2.Node; import net.ivoa.xml.vospace.v2.Node;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
...@@ -245,10 +247,16 @@ public class NodeUtils { ...@@ -245,10 +247,16 @@ public class NodeUtils {
} }
public static String getVosPath(Node myNode) { public static String getVosPath(Node myNode) {
return getVosPath(myNode.getUri());
}
String nodeUri = myNode.getUri(); public static String getVosPath(String nodeUri) {
try {
return nodeUri.replaceAll("vos://[^/]+", ""); URI uri = new URI(nodeUri);
return uri.getPath();
} catch (URISyntaxException ex) {
throw new RuntimeException(ex);
}
} }
} }
...@@ -271,6 +271,15 @@ public class NodeUtilsTest { ...@@ -271,6 +271,15 @@ public class NodeUtilsTest {
assertEquals("/mynode/child1/child2", NodeUtils.getVosPath(node)); assertEquals("/mynode/child1/child2", NodeUtils.getVosPath(node));
} }
@Test
public void testGetVosPathSpecialChars() {
Node node = new DataNode();
node.setUri("vos://example.com!vospace/mynode/(%20+%20)/child2");
assertEquals("/mynode/( + )/child2", NodeUtils.getVosPath(node));
}
@Test @Test
public void testGetParentPath() { public void testGetParentPath() {
assertEquals("/node1/node2", NodeUtils.getParentPath("/node1/node2/node2")); assertEquals("/node1/node2", NodeUtils.getParentPath("/node1/node2/node2"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment