diff options
author | Kenny Root <kenny@the-b.org> | 2009-07-12 10:33:28 -0500 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2009-09-14 17:45:04 -0700 |
commit | fc01794f33057862a361a0d0113630c58befc21b (patch) | |
tree | 9f6096454c1ad47c4c3a9b5b2e2ef40517a02543 /core/java/android/net/Uri.java | |
parent | f9d9cf1ec146d8edbb2094416a823cd7b43098d0 (diff) | |
download | frameworks_base-fc01794f33057862a361a0d0113630c58befc21b.zip frameworks_base-fc01794f33057862a361a0d0113630c58befc21b.tar.gz frameworks_base-fc01794f33057862a361a0d0113630c58befc21b.tar.bz2 |
Make Uri.parseUserPart, parseHost, and parsePort symmetric
Currently parseUserPart uses the encoded authority to split the URI
into user and non-user parts, but the parseHost and parsePort uses
the decoded URI to split the URI into non-host, host, and port parts.
This gives unexpected results when %40 ('@') and %3a (':') is used
in a URI:
Uri test = Uri.parse("http://bob%40lee%3ajr@example.com:42/");
test.getUserInfo() => "bob@lee:jr"
test.getHost() => "lee:jr@example.com" (should be "example.com")
test.getPort() => -1 (should be 42)
Diffstat (limited to 'core/java/android/net/Uri.java')
-rw-r--r-- | core/java/android/net/Uri.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/core/java/android/net/Uri.java b/core/java/android/net/Uri.java index 298be3b..9a1b65d 100644 --- a/core/java/android/net/Uri.java +++ b/core/java/android/net/Uri.java @@ -1028,7 +1028,7 @@ public abstract class Uri implements Parcelable, Comparable<Uri> { } private String parseHost() { - String authority = getAuthority(); + String authority = getEncodedAuthority(); if (authority == null) { return null; } @@ -1037,9 +1037,11 @@ public abstract class Uri implements Parcelable, Comparable<Uri> { int userInfoSeparator = authority.indexOf('@'); int portSeparator = authority.indexOf(':', userInfoSeparator); - return portSeparator == NOT_FOUND + String encodedHost = portSeparator == NOT_FOUND ? authority.substring(userInfoSeparator + 1) : authority.substring(userInfoSeparator + 1, portSeparator); + + return decode(encodedHost); } private volatile int port = NOT_CALCULATED; @@ -1051,7 +1053,7 @@ public abstract class Uri implements Parcelable, Comparable<Uri> { } private int parsePort() { - String authority = getAuthority(); + String authority = getEncodedAuthority(); if (authority == null) { return -1; } @@ -1065,7 +1067,7 @@ public abstract class Uri implements Parcelable, Comparable<Uri> { return -1; } - String portString = authority.substring(portSeparator + 1); + String portString = decode(authority.substring(portSeparator + 1)); try { return Integer.parseInt(portString); } catch (NumberFormatException e) { |