Commit aafc934e authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Update URLConnection#testLenientUrlToUriNul.

Our earlier behaviour was somewhat broken. We'd accept
hosts with \u0000 in them, and then produce a request with
a bad Host header. We now fail on such requests, so add a
unit test to exercise that new behaviour.

The ideal behaviour might be to be lenient and escape characters
that we don't like. (This would involve using the URI from
URL#toUriLenient to populate the Host header. I attempted that
but it has the side effect of introducing a new set of
incompatibilities).

Change-Id: I38a0d39124dc5ca766a6e963e72b0250440e82ee
parent c58569f5
......@@ -1913,7 +1913,22 @@ public final class URLConnectionTest extends TestCase {
}
public void testLenientUrlToUriNul() throws Exception {
testUrlToUriMapping("\u0000", "%00", "%00", "%00", "%00"); // RI fails this
// On JB-MR2 and below, we would allow a host containing \u0000
// and then generate a request with a Host header that violated RFC2616.
// We now reject such hosts.
//
// The ideal behaviour here is to be "lenient" about the host and rewrite
// it, but attempting to do so introduces a new range of incompatible
// behaviours.
testUrlToUriMapping("\u0000", null, "%00", "%00", "%00"); // RI fails this
}
public void testHostWithNul() throws Exception {
URL url = new URL("http://host\u0000/");
try {
url.openStream();
fail();
} catch (IllegalArgumentException expected) {}
}
private void testUrlToUriMapping(String string, String asAuthority, String asFile,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment