Resolve reference Uris correctly.

Ignore the path of the base Uri if the reference starts with "/".
Spec - http://tools.ietf.org/html/rfc3986#section-5.2.2
This commit is contained in:
Oliver Woodman 2014-09-19 18:31:17 +01:00
parent bf95592b2c
commit 4e96caa623

View File

@ -163,12 +163,22 @@ public final class Util {
if (stringUri == null) { if (stringUri == null) {
return baseUri; return baseUri;
} }
Uri uri = Uri.parse(stringUri); if (baseUri == null) {
if (!uri.isAbsolute() && baseUri != null) { return Uri.parse(stringUri);
uri = Uri.withAppendedPath(baseUri, stringUri);
} }
if (stringUri.startsWith("/")) {
return new Uri.Builder()
.scheme(baseUri.getScheme())
.authority(baseUri.getAuthority())
.appendEncodedPath(stringUri)
.build();
}
Uri uri = Uri.parse(stringUri);
if (uri.isAbsolute()) {
return uri; return uri;
} }
return Uri.withAppendedPath(baseUri, stringUri);
}
/** /**
* Returns the index of the largest value in an array that is less than (or optionally equal to) * Returns the index of the largest value in an array that is less than (or optionally equal to)