Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/org/archive/url/URLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,16 @@ public static HandyURL parse(String urlString) throws URISyntaxException {
String colonPort = null;

int atIndex = uriAuthority.indexOf(COMMERCIAL_AT);
int portColonIndex = uriAuthority.indexOf(COLON,(atIndex<0)?0:atIndex);
int portColonIndex = -1;
int startColonIndex = 0;
if (atIndex > -1) {
startColonIndex = atIndex;
}
if (uriAuthority.charAt(startColonIndex) == '[') {
// IPv6 address
startColonIndex = uriAuthority.indexOf(']', (startColonIndex + 1));
}
portColonIndex = uriAuthority.indexOf(COLON, startColonIndex);

if(atIndex<0 && portColonIndex<0) {
// most common case: neither userinfo nor port
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/archive/url/URLRegexTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public static String hostToSURT(String host) {
// TODO: ensure we DONT reverse IP addresses!
String parts[] = host.split("\\.",-1);
if(parts.length == 1) {
// strip enclosing "[" and "]" from IPv6 hosts
if (host.charAt(0) == '[' && host.charAt(host.length() - 1) == ']') {
return host.substring(1, host.length() - 1);
}
return host;
}
StringBuilder sb = new StringBuilder(host.length());
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/archive/url/URLParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public void testParse() throws UnsupportedEncodingException, URISyntaxException
checkParse(" \n http://:****@www.archive.org:8080/inde\rx.html?query#foo \r\n \t ",
null, "http", "", "****", "www.archive.org", 8080, "/index.html", "query", "foo",
"http://:****@www.archive.org:8080/index.html?query#foo", "/index.html?query");
checkParse("https://[2600:1f18:200d:fb00:2b74:867c:ab0c:150a]/robots.txt", null, "https", null, null,
"[2600:1f18:200d:fb00:2b74:867c:ab0c:150a]", -1, "/robots.txt", null, null,
"https://[2600:1f18:200d:fb00:2b74:867c:ab0c:150a]/robots.txt", "/robots.txt");
}

private void checkParse(String s, String opaque, String scheme, String authUser,
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/archive/url/WaybackURLKeyMakerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public void testMakeKey() throws URISyntaxException {
assertEquals("org,archive)/goo?a&b", km.makeKey("http://archive.org/goo/?b&a"));
assertEquals("org,archive)/goo?a=1&a=2&b", km.makeKey("http://archive.org/goo/?a=2&b&a=1"));
assertEquals("org,archive)/", km.makeKey("http://archive.org:/"));
assertEquals("192,211,203,34)/robots.txt", km.makeKey("https://34.203.211.192/robots.txt"));
assertEquals("2600:1f18:200d:fb00:2b74:867c:ab0c:150a)/robots.txt",
km.makeKey("https://[2600:1f18:200d:fb00:2b74:867c:ab0c:150a]/robots.txt"));
}

}