Merge "Adjust URI host parsing to stop on \ character." into lmp-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5ed5d15e66
@@ -714,6 +714,10 @@ public abstract class Uri implements Parcelable, Comparable<Uri> {
|
|||||||
LOOP: while (end < length) {
|
LOOP: while (end < length) {
|
||||||
switch (uriString.charAt(end)) {
|
switch (uriString.charAt(end)) {
|
||||||
case '/': // Start of path
|
case '/': // Start of path
|
||||||
|
case '\\':// Start of path
|
||||||
|
// Per http://url.spec.whatwg.org/#host-state, the \ character
|
||||||
|
// is treated as if it were a / character when encountered in a
|
||||||
|
// host
|
||||||
case '?': // Start of query
|
case '?': // Start of query
|
||||||
case '#': // Start of fragment
|
case '#': // Start of fragment
|
||||||
break LOOP;
|
break LOOP;
|
||||||
@@ -752,6 +756,10 @@ public abstract class Uri implements Parcelable, Comparable<Uri> {
|
|||||||
case '#': // Start of fragment
|
case '#': // Start of fragment
|
||||||
return ""; // Empty path.
|
return ""; // Empty path.
|
||||||
case '/': // Start of path!
|
case '/': // Start of path!
|
||||||
|
case '\\':// Start of path!
|
||||||
|
// Per http://url.spec.whatwg.org/#host-state, the \ character
|
||||||
|
// is treated as if it were a / character when encountered in a
|
||||||
|
// host
|
||||||
break LOOP;
|
break LOOP;
|
||||||
}
|
}
|
||||||
pathStart++;
|
pathStart++;
|
||||||
|
|||||||
@@ -192,6 +192,12 @@ public class UriTest extends TestCase {
|
|||||||
assertEquals("a:a@example.com:a@example2.com", uri.getAuthority());
|
assertEquals("a:a@example.com:a@example2.com", uri.getAuthority());
|
||||||
assertEquals("example2.com", uri.getHost());
|
assertEquals("example2.com", uri.getHost());
|
||||||
assertEquals(-1, uri.getPort());
|
assertEquals(-1, uri.getPort());
|
||||||
|
assertEquals("/path", uri.getPath());
|
||||||
|
|
||||||
|
uri = Uri.parse("http://a.foo.com\\.example.com/path");
|
||||||
|
assertEquals("a.foo.com", uri.getHost());
|
||||||
|
assertEquals(-1, uri.getPort());
|
||||||
|
assertEquals("\\.example.com/path", uri.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
|
|||||||
Reference in New Issue
Block a user