Skip to content

Commit 9e41abc

Browse files
Strip empty port, do not fail
1 parent bb36b6a commit 9e41abc

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/main/java/org/archive/url/URLParser.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,20 @@ public static HandyURL parse(String urlString) throws URISyntaxException {
246246
colonPort = uriAuthority.substring(portColonIndex);
247247
}
248248
if(colonPort != null) {
249-
if(colonPort.startsWith(":")) {
250-
try {
251-
port = Integer.parseInt(colonPort.substring(1));
252-
} catch(NumberFormatException e) {
253-
throw new URISyntaxException(urlString, "bad port "
254-
+ colonPort.substring(1));
255-
}
256-
} else {
257-
// XXX: what's happened?!
258-
}
249+
if(colonPort.startsWith(":")) {
250+
if (colonPort.length() == 1) {
251+
// a bare colon (http://example.com:/), use default port
252+
} else {
253+
try {
254+
port = Integer.parseInt(colonPort.substring(1));
255+
} catch(NumberFormatException e) {
256+
throw new URISyntaxException(urlString, "bad port "
257+
+ colonPort.substring(1));
258+
}
259+
}
260+
} else {
261+
// XXX: what's happened?!
262+
}
259263
}
260264
if(userInfo != null) {
261265
int passColonIndex = userInfo.indexOf(COLON);

src/test/java/org/archive/url/IAURLCanonicalizerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public void testFull() throws URISyntaxException {
1212
compCan(iaC,"https://www.archive.org:80/","https://archive.org:80/");
1313
compCan(iaC,"http://www.archive.org:443/","http://archive.org:443/");
1414
compCan(iaC,"https://www.archive.org:443/","https://archive.org/");
15+
compCan(iaC,"http://www.archive.org:/","http://archive.org/");
1516
compCan(iaC,"http://www.archive.org/big/","http://archive.org/big");
1617
compCan(iaC,"dns:www.archive.org","dns:www.archive.org");
1718

src/test/java/org/archive/url/WaybackURLKeyMakerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void testMakeKey() throws URISyntaxException {
2222
assertEquals("org,archive)/goo", km.makeKey("http://archive.org/goo/?"));
2323
assertEquals("org,archive)/goo?a&b", km.makeKey("http://archive.org/goo/?b&a"));
2424
assertEquals("org,archive)/goo?a=1&a=2&b", km.makeKey("http://archive.org/goo/?a=2&b&a=1"));
25+
assertEquals("org,archive)/", km.makeKey("http://archive.org:/"));
2526
}
2627

2728
}

0 commit comments

Comments
 (0)