Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) be more tolerant against missing ports in url "http://yacy.net:/" is now interpreted as "http://yacy.net/" See: http://www.yacy-forum.de/viewtopic.php?p=27102

thelid38ef0493d16
diff --git a/source/de/anomic/net/URL.java b/source/de/anomic/net/URL.java
index 019eae042..f277c5ec7 100644
--- a/source/de/anomic/net/URL.java
+++ b/source/de/anomic/net/URL.java
@@ -371,13 +371,15 @@ public class URL {
private void identPort(String inputURL) throws MalformedURLException {
// identify ref in file
- int r = host.indexOf(':');
+ int r = this.host.indexOf(':');
if (r < 0) {
this.port = -1;
- } else {
+ } else {
try {
- this.port = Integer.parseInt(host.substring(r + 1));
- this.host = host.substring(0, r);
+ String portStr = this.host.substring(r + 1);
+ if (portStr.trim().length() > 0) this.port = Integer.parseInt(portStr);
+ else this.port = -1;
+ this.host = this.host.substring(0, r);
} catch (NumberFormatException e) {
throw new MalformedURLException("wrong port in host fragment '" + this.host + "' of input url '" + inputURL + "'");
}
diff --git a/test/de/anomic/net/URLTest.java b/test/de/anomic/net/URLTest.java
index 518d201b5..a6a349a0d 100644
--- a/test/de/anomic/net/URLTest.java
+++ b/test/de/anomic/net/URLTest.java
@@ -37,4 +37,27 @@ public class URLTest extends TestCase {
}
}
+ public void testIdentPort() throws MalformedURLException {
+ String[][] testStrings = new String[][] {
+ new String[]{"http://www.yacy.net:","http://www.yacy.net/"},
+ new String[]{"http://www.yacy.net:-1","http://www.yacy.net/"},
+ new String[]{"http://www.yacy.net:/","http://www.yacy.net/"},
+ new String[]{"http://www.yacy.net: /","http://www.yacy.net/"}
+ };
+
+ for (int i=0; i < testStrings.length; i++) {
+ // desired conversion result
+ System.out.print("testIdentPort: " + testStrings[i][0]);
+ String shouldBe = testStrings[i][1];
+
+ // conversion result
+ String resolvedURL = (new URL(testStrings[i][0])).toString();
+
+ // test if equal
+ assertEquals(shouldBe,resolvedURL);
+ System.out.println(" -> " + resolvedURL);
+
+ }
+ }
+
}