From 8a1f1d96b31ff92b7f7210bfbb739252a35f654c Mon Sep 17 00:00:00 2001 From: theli Date: Tue, 18 Jul 2006 04:48:18 +0000 Subject: [PATCH] *) Bugfix for url concatenation. Relative urls with / or http:// at the beginning were not handled correctly on url concatenation via new URL(URL,relPath). See: http://www.yacy-forum.de/viewtopic.php?t=2623 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2297 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/net/URL.java | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/source/de/anomic/net/URL.java b/source/de/anomic/net/URL.java index d58bc355a..2281cd291 100644 --- a/source/de/anomic/net/URL.java +++ b/source/de/anomic/net/URL.java @@ -38,6 +38,10 @@ public class URL { private int port; public URL(String url) throws MalformedURLException { + parseURLString(url); + } + + public void parseURLString(String url) throws MalformedURLException { // identify protocol int p = url.indexOf("://"); if (p < 0) throw new MalformedURLException("protocol is not given in '" + url + "'"); @@ -77,16 +81,19 @@ public class URL { public URL(URL baseURL, String relPath) throws MalformedURLException { if (baseURL == null) throw new MalformedURLException("base URL is null"); - if (relPath.startsWith("/")) relPath = relPath.substring(1); - this.protocol = baseURL.protocol; - this.host = baseURL.host; - this.port = baseURL.port; - this.path = (baseURL.path.endsWith("/")) ? (baseURL.path + relPath) : (baseURL.path + "/" + relPath); - this.quest = baseURL.quest; - this.ref = baseURL.ref; - - identRef(); - identQuest(); + if (relPath.toLowerCase().startsWith("http://")) parseURLString(relPath); + else { + this.protocol = baseURL.protocol; + this.host = baseURL.host; + this.port = baseURL.port; + if (relPath.startsWith("/")) this.path = relPath; + else this.path = (baseURL.path.endsWith("/")) ? (baseURL.path + relPath) : (baseURL.path + "/" + relPath); + this.quest = baseURL.quest; + this.ref = baseURL.ref; + + identRef(); + identQuest(); + } } public URL(String protocol, String host, int port, String path) throws MalformedURLException {