Merge cherrypicks of [4667264, 4667744, 4667382, 4666687, 4667506, 4667745, 4667225, 4667226, 4667227, 4667228, 4668483, 4668486, 4668487, 4668489, 4666733, 4668492, 4668493, 4668495, 4667548, 4667482, 4667549, 4667550, 4667551, 4667552, 4667553, 4667554, 4667555, 4667556, 4666734, 4666688, 4668511, 4668531, 4667265] into pi-release
Change-Id: I64397a4df95e908e4b9b77dade0a4f619c41640f
diff --git a/luni/src/test/java/libcore/java/net/URLTest.java b/luni/src/test/java/libcore/java/net/URLTest.java
index 1ff9b33..066442e 100644
--- a/luni/src/test/java/libcore/java/net/URLTest.java
+++ b/luni/src/test/java/libcore/java/net/URLTest.java
@@ -582,6 +582,26 @@
assertEquals("http://host/a/c", url.toString()); // RI doesn't canonicalize
}
+ public void testPathContainsBackslash() throws Exception {
+ URL url = new URL("http://host\\path@foo");
+ assertEquals("\\path@foo", url.getPath());
+ assertEquals("host", url.getHost());
+ }
+
+ public void testQueryContainsForwardSlash() throws Exception {
+ URL url = new URL("http://host?query/foo");
+ assertEquals("", url.getPath());
+ assertEquals("host", url.getHost());
+ assertEquals("query/foo", url.getQuery());
+ }
+
+ public void testFragmentContainsForwardSlash() throws Exception {
+ URL url = new URL("http://host#fragment/foo");
+ assertEquals("", url.getPath());
+ assertEquals("host", url.getHost());
+ assertEquals("fragment/foo", url.getRef());
+ }
+
public void testRelativePathAndFragment() throws Exception {
URL base = new URL("http://host/file");
assertEquals("http://host/another#fragment", new URL(base, "another#fragment").toString());
diff --git a/ojluni/src/main/java/java/net/URLStreamHandler.java b/ojluni/src/main/java/java/net/URLStreamHandler.java
index d5380c1..01862f6 100644
--- a/ojluni/src/main/java/java/net/URLStreamHandler.java
+++ b/ojluni/src/main/java/java/net/URLStreamHandler.java
@@ -167,12 +167,25 @@
if (!isUNCName && (start <= limit - 2) && (spec.charAt(start) == '/') &&
(spec.charAt(start + 1) == '/')) {
start += 2;
+ // BEGIN Android-changed: Check for all hostname termination chars. http://b/110955991
+ /*
i = spec.indexOf('/', start);
if (i < 0 || i > limit) {
i = spec.indexOf('?', start);
if (i < 0 || i > limit)
i = limit;
}
+ */
+ LOOP: for (i = start; i < limit; i++) {
+ switch (spec.charAt(i)) {
+ case '/': // Start of path
+ case '\\': // Start of path - see https://url.spec.whatwg.org/#host-state
+ case '?': // Start of query
+ case '#': // Start of fragment
+ break LOOP;
+ }
+ }
+ // END Android-changed: Check for all hostname termination chars. http://b/110955991
host = authority = spec.substring(start, i);
@@ -266,7 +279,9 @@
// Parse the file path if any
if (start < limit) {
- if (spec.charAt(start) == '/') {
+ // Android-changed: Check for all hostname termination chars. http://b/110955991
+ // if (spec.charAt(start) == '/') {
+ if (spec.charAt(start) == '/' || spec.charAt(start) == '\\') {
path = spec.substring(start, limit);
} else if (path != null && path.length() > 0) {
isRelPath = true;