diff options
| author | 2017-11-08 00:38:27 +0000 | |
|---|---|---|
| committer | 2017-11-08 00:38:27 +0000 | |
| commit | 97ff9f9d27277b4d94eef0caf1afaae691e0ba6d (patch) | |
| tree | b2010bc1a8ff5a3f7781e40b22a62e10ec7b89d8 | |
| parent | c74eab1d53089b9ec064b70c0bdc48b321ca0e42 (diff) | |
| parent | 2edd31e7fc25dc879c22b6550a823e391bbc440f (diff) | |
Adjust Uri host parsing to use last instead of first @. am: cd6228dd37 am: 6a9c7c4814 am: 4158c9fbf3 am: eee677386e am: 49e5fca362 am: 240b55de2c am: 3ac5dabc21 am: f61daaa333 am: 49dfdd66cc am: eb4598afba am: a2149abe3a am: 560fb5d050
am: 2edd31e7fc
Change-Id: Ic915bece1025d8ad8a0ed05e9b20afa9bfcdd811
| -rw-r--r-- | core/java/android/net/Uri.java | 6 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/net/UriTest.java | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/core/java/android/net/Uri.java b/core/java/android/net/Uri.java index d5377c717366..9edcc0e9b8d4 100644 --- a/core/java/android/net/Uri.java +++ b/core/java/android/net/Uri.java @@ -1066,7 +1066,7 @@ public abstract class Uri implements Parcelable, Comparable<Uri> { return null; } - int end = authority.indexOf('@'); + int end = authority.lastIndexOf('@'); return end == NOT_FOUND ? null : authority.substring(0, end); } @@ -1090,7 +1090,7 @@ public abstract class Uri implements Parcelable, Comparable<Uri> { } // Parse out user info and then port. - int userInfoSeparator = authority.indexOf('@'); + int userInfoSeparator = authority.lastIndexOf('@'); int portSeparator = authority.indexOf(':', userInfoSeparator); String encodedHost = portSeparator == NOT_FOUND @@ -1116,7 +1116,7 @@ public abstract class Uri implements Parcelable, Comparable<Uri> { // Make sure we look for the port separtor *after* the user info // separator. We have URLs with a ':' in the user info. - int userInfoSeparator = authority.indexOf('@'); + int userInfoSeparator = authority.lastIndexOf('@'); int portSeparator = authority.indexOf(':', userInfoSeparator); if (portSeparator == NOT_FOUND) { diff --git a/core/tests/coretests/src/android/net/UriTest.java b/core/tests/coretests/src/android/net/UriTest.java index 6fa28b1ccdaa..27b7f9e185bb 100644 --- a/core/tests/coretests/src/android/net/UriTest.java +++ b/core/tests/coretests/src/android/net/UriTest.java @@ -187,6 +187,11 @@ public class UriTest extends TestCase { uri = Uri.parse("http://localhost"); assertEquals("localhost", uri.getHost()); assertEquals(-1, uri.getPort()); + + uri = Uri.parse("http://a:a@example.com:a@example2.com/path"); + assertEquals("a:a@example.com:a@example2.com", uri.getAuthority()); + assertEquals("example2.com", uri.getHost()); + assertEquals(-1, uri.getPort()); } @SmallTest |