Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
fix: resolve url without path but searchpart e.g. http://yacy.net?q=test was resolved as host "yacy.net?q=test" now host="yacy.net" path="/" fixes http://mantis.tokeek.de/view.php?id=47
regerbb8181b2be97
diff --git a/source/net/yacy/cora/document/id/MultiProtocolURL.java b/source/net/yacy/cora/document/id/MultiProtocolURL.javaindex c9af0763e..1fe482bc2 100644--- a/source/net/yacy/cora/document/id/MultiProtocolURL.java+++ b/source/net/yacy/cora/document/id/MultiProtocolURL.java@@ -164,7 +164,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolUif (url.length() < p + 4) throw new MalformedURLException("URL not parseable: '" + url + "'");if (!this.protocol.equals("file") && url.substring(p + 1, p + 3).equals("//")) {// identify host, userInfo and file for http and ftp protocol- final int q = url.indexOf('/', p + 3);+ int q = url.indexOf('/', p + 3);+ if (q < 0) q = url.indexOf("?", p + 3); // check for www.test.com?searchpartint r;if (q < 0) {if ((r = url.indexOf('@', p + 3)) < 0) {@@ -183,11 +184,11 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolUthis.userInfo = this.host.substring(0, r);this.host = this.host.substring(r + 1).intern();}- this.path = url.substring(q);+ this.path = url.substring(q); // may result in "?searchpart" (resolveBackpath prepends a "/" )}if (this.host.length() < 4 && !this.protocol.equals("file")) throw new MalformedURLException("host too short: '" + this.host + "', url = " + url);if (this.host.indexOf('&') >= 0) throw new MalformedURLException("invalid '&' in host");- this.path = resolveBackpath(this.path);+ this.path = resolveBackpath(this.path); // adds "/" if missingidentPort(url, (isHTTP() ? 80 : (isHTTPS() ? 443 : (isFTP() ? 21 : (isSMB() ? 445 : -1)))));identAnchor();identSearchpart();diff --git a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java b/test/net/yacy/cora/document/id/MultiProtocolURLTest.javaindex 046083b8d..aae13fa1a 100644--- a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java+++ b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java@@ -113,6 +113,34 @@ public class MultiProtocolURLTest {}}++ @Test+ public void testGetHost() throws MalformedURLException {+ String[][] testStrings = new String[][]{+ // teststring , expectedresult+ new String[]{"http://www.yacy.net", "www.yacy.net"},+ new String[]{"http://www.yacy.net:8090", "www.yacy.net"},+ new String[]{"http://www.yacy.net/test?query=test", "www.yacy.net"},+ new String[]{"http://www.yacy.net/?query=test", "www.yacy.net"},+ new String[]{"http://www.yacy.net?query=test", "www.yacy.net"},+ new String[]{"http://www.yacy.net:?query=test", "www.yacy.net"},+ new String[]{"//www.yacy.net:?query=test", "www.yacy.net"},+ };++ for (int i = 0; i < testStrings.length; i++) {+ // desired conversion result+ System.out.print("testGetHost: " + testStrings[i][0]);+ String shouldBe = testStrings[i][1];++ // conversion result+ String resolvedHost = new MultiProtocolURL(testStrings[i][0]).getHost();++ // test if equal+ assertEquals(shouldBe, resolvedHost);+ System.out.println(" -> " + resolvedHost);++ }+ }}