summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-10-27 15:53:18 +0000
committerNarayan Kamath <narayan@google.com>2014-10-28 10:19:06 +0000
commit435edc3fa9abd3f8d324c9dd4279a165051052ba (patch)
tree162132f55a9fda4546937324842df6209b375169
parentf7ba96dcf561cc95389d19b81f51828315b4a2e8 (diff)
downloadlibcore-435edc3fa9abd3f8d324c9dd4279a165051052ba.zip
libcore-435edc3fa9abd3f8d324c9dd4279a165051052ba.tar.gz
libcore-435edc3fa9abd3f8d324c9dd4279a165051052ba.tar.bz2
Allow "_" in URIs.
Note that this is contrary to RFC-2396, which only allows alphanumeric characters and hyphens. We need this change because internet hosts out there clearly don't care enough about standards. bug: 18023709 Change-Id: I9459f58d49ccc68af887a14c889eaa60b6c3150d
-rw-r--r--luni/src/main/java/java/net/URI.java5
-rw-r--r--luni/src/test/java/libcore/java/net/URITest.java8
2 files changed, 10 insertions, 3 deletions
diff --git a/luni/src/main/java/java/net/URI.java b/luni/src/main/java/java/net/URI.java
index f206473..60bb5db 100644
--- a/luni/src/main/java/java/net/URI.java
+++ b/luni/src/main/java/java/net/URI.java
@@ -571,7 +571,10 @@ public final class URI implements Comparable<URI>, Serializable {
private boolean isValidDomainName(String host) {
try {
- UriCodec.validateSimple(host, "-.");
+ // The RFCs don't permit underscores in hostnames, but URI has to because
+ // a certain large website doesn't seem to care about standards and specs.
+ // See bugs 18023709, 17579865 and 18016625.
+ UriCodec.validateSimple(host, "_-.");
} catch (URISyntaxException e) {
return false;
}
diff --git a/luni/src/test/java/libcore/java/net/URITest.java b/luni/src/test/java/libcore/java/net/URITest.java
index 7f4c086..c87433a 100644
--- a/luni/src/test/java/libcore/java/net/URITest.java
+++ b/luni/src/test/java/libcore/java/net/URITest.java
@@ -702,11 +702,15 @@ public final class URITest extends TestCase {
}
// http://code.google.com/p/android/issues/detail?id=37577
+ // http://b/18023709
+ // http://b/17579865
+ // http://b/18016625
public void testUnderscore() throws Exception {
URI uri = new URI("http://a_b.c.d.net/");
assertEquals("a_b.c.d.net", uri.getAuthority());
- // The RFC's don't permit underscores in hostnames, and neither does URI (unlike URL).
- assertNull(uri.getHost());
+ // The RFC's don't permit underscores in hostnames, but URI has to because
+ // a certain large website doesn't seem to care about standards and specs.
+ assertEquals("a_b.c.d.net", uri.getHost());
}
// Adding a new test? Consider adding an equivalent test to URLTest.java