mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
*) 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 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2852 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
51a2a1f558
commit
d38ef0493d
|
@ -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 {
|
||||
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 + "'");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user