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
No related branches found
No related tags found
No related merge requests found
Pipeline #7980 passed
......@@ -5,6 +5,8 @@
*/
package it.inaf.oats.vospace.datamodel;
import java.net.URI;
import java.net.URISyntaxException;
import net.ivoa.xml.vospace.v2.Node;
import java.net.URLDecoder;
import java.net.URLEncoder;
......@@ -245,10 +247,16 @@ public class NodeUtils {
}
public static String getVosPath(Node myNode) {
return getVosPath(myNode.getUri());
}
String nodeUri = myNode.getUri();
return nodeUri.replaceAll("vos://[^/]+", "");
public static String getVosPath(String nodeUri) {
try {
URI uri = new URI(nodeUri);
return uri.getPath();
} catch (URISyntaxException ex) {
throw new RuntimeException(ex);
}
}
}
......@@ -271,6 +271,15 @@ public class NodeUtilsTest {
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
public void testGetParentPath() {
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