summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adam Vartanian <flooey@google.com> 2017-11-07 21:41:55 +0000
committer android-build-merger <android-build-merger@google.com> 2017-11-07 21:41:55 +0000
commit240b55de2c2079833a78a981b5ce50cd174a4002 (patch)
tree813803c1798edde7100ba75c3438efb645b7b47f
parentbc56010856abc76d1a212b5e3e9c5896d839b911 (diff)
parent49e5fca36208ec439dd6f76999d4ce8fcdeabd58 (diff)
Adjust Uri host parsing to use last instead of first @. am: cd6228dd37 am: 6a9c7c4814 am: 4158c9fbf3 am: eee677386e
am: 49e5fca362 Change-Id: Id6f38542623d768bebcfae7e79e8e49450329037
-rw-r--r--core/java/android/net/Uri.java6
-rw-r--r--core/tests/coretests/src/android/net/UriTest.java5
2 files changed, 8 insertions, 3 deletions
diff --git a/core/java/android/net/Uri.java b/core/java/android/net/Uri.java
index 4a8dfbc5aefe..06bb07b7629f 100644
--- a/core/java/android/net/Uri.java
+++ b/core/java/android/net/Uri.java
@@ -1065,7 +1065,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);
}
@@ -1089,7 +1089,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
@@ -1115,7 +1115,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