mirror of
https://github.com/etesync/android
synced 2025-06-03 14:49:00 +00:00
Specify encoding details of member names passed to WebDavResource (fixes #482)
This commit is contained in:
parent
c6950b1c16
commit
ed2a0419ad
@ -145,18 +145,24 @@ public class WebDavResourceTest extends InstrumentationTestCase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (String path : requestPaths) {
|
for (String path : requestPaths) {
|
||||||
WebDavResource davSlash = new WebDavResource(davCollection, path);
|
WebDavResource davSlash = new WebDavResource(davCollection, new URI(path));
|
||||||
davSlash.propfind(Mode.CARDDAV_COLLECTIONS);
|
davSlash.propfind(Mode.CARDDAV_COLLECTIONS);
|
||||||
assertEquals(new URI(principalOK), davSlash.getCurrentUserPrincipal());
|
assertEquals(new URI(principalOK), davSlash.getCurrentUserPrincipal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testStrangeMemberNames() throws Exception {
|
||||||
|
// construct a WebDavResource from a base collection and a member which is an encoded URL (see https://github.com/bitfireAT/davdroid/issues/482)
|
||||||
|
WebDavResource dav = new WebDavResource(davCollection, "http%3A%2F%2Fwww.invalid.example%2Fm8%2Ffeeds%2Fcontacts%2Fmaria.mueller%2540gmail.com%2Fbase%2F5528abc5720cecc.vcf");
|
||||||
|
dav.get("text/vcard");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* test normal HTTP/WebDAV */
|
/* test normal HTTP/WebDAV */
|
||||||
|
|
||||||
public void testPropfindRedirection() throws Exception {
|
public void testPropfindRedirection() throws Exception {
|
||||||
// PROPFIND redirection
|
// PROPFIND redirection
|
||||||
WebDavResource redirected = new WebDavResource(baseDAV, "/redirect/301?to=/dav/");
|
WebDavResource redirected = new WebDavResource(baseDAV, new URI("/redirect/301?to=/dav/"));
|
||||||
redirected.propfind(Mode.CURRENT_USER_PRINCIPAL);
|
redirected.propfind(Mode.CURRENT_USER_PRINCIPAL);
|
||||||
assertEquals("/dav/", redirected.getLocation().getPath());
|
assertEquals("/dav/", redirected.getLocation().getPath());
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ exports.getBodyParts = function(conf) {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
/* non-existing file */
|
/* non-existing member */
|
||||||
new RoboHydraHeadDAV({
|
new RoboHydraHeadDAV({
|
||||||
path: "/dav/collection/new.file",
|
path: "/dav/collection/new.file",
|
||||||
handler: function(req,res,next) {
|
handler: function(req,res,next) {
|
||||||
@ -238,7 +238,7 @@ exports.getBodyParts = function(conf) {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
/* existing file */
|
/* existing member */
|
||||||
new RoboHydraHeadDAV({
|
new RoboHydraHeadDAV({
|
||||||
path: "/dav/collection/existing.file",
|
path: "/dav/collection/existing.file",
|
||||||
handler: function(req,res,next) {
|
handler: function(req,res,next) {
|
||||||
@ -255,6 +255,15 @@ exports.getBodyParts = function(conf) {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
/* existing member with encoded URL as file name */
|
||||||
|
new RoboHydraHeadDAV({
|
||||||
|
path: "/dav/http%253A%252F%252Fwww.invalid.example%252Fm8%252Ffeeds%252Fcontacts%252Fmaria.mueller%252540gmail.com%252Fbase%252F5528abc5720cecc.vcf",
|
||||||
|
handler: function(req,res,next) {
|
||||||
|
if (req.method == "GET")
|
||||||
|
res.statusCode = 200;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
/* address-book multiget */
|
/* address-book multiget */
|
||||||
new RoboHydraHeadDAV({
|
new RoboHydraHeadDAV({
|
||||||
path: "/dav/addressbooks/default.vcf/",
|
path: "/dav/addressbooks/default.vcf/",
|
||||||
|
@ -39,7 +39,7 @@ public class URIUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a received absolute/relative URL and generate a normalized URI that can be compared.
|
* Parse a received absolute/relative URL and generate a normalized URI that can be compared.
|
||||||
* @param original URI to be parsed, may be absolute or relative
|
* @param original URI to be parsed, may be absolute or relative. Encoded characters will be decoded!
|
||||||
* @param mustBePath true if it's known that original is a path (may contain ":") and not an URI, i.e. ":" is not the scheme separator
|
* @param mustBePath true if it's known that original is a path (may contain ":") and not an URI, i.e. ":" is not the scheme separator
|
||||||
* @return normalized URI
|
* @return normalized URI
|
||||||
* @throws URISyntaxException
|
* @throws URISyntaxException
|
||||||
@ -72,7 +72,8 @@ public class URIUtils {
|
|||||||
|
|
||||||
URI uri = new URI(repaired);
|
URI uri = new URI(repaired);
|
||||||
URI normalized = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment());
|
URI normalized = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment());
|
||||||
Log.v(TAG, "Normalized URL " + original + " -> " + normalized.toASCIIString());
|
Log.v(TAG, "Normalized URI " + original + " -> " + normalized.toASCIIString() + " assuming that it was " +
|
||||||
|
(mustBePath ? "a path name" : "an URI or path name"));
|
||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,12 +141,14 @@ public class WebDavResource {
|
|||||||
/**
|
/**
|
||||||
* Creates a WebDavResource representing a member of the parent collection.
|
* Creates a WebDavResource representing a member of the parent collection.
|
||||||
* @param parent Parent collection
|
* @param parent Parent collection
|
||||||
* @param member File name of the member. This may contain ":" without leading "./"!
|
* @param member File name of the member, unescaped. This may contain ":" without leading "./"!
|
||||||
|
* To create a new collection with a relative path that may not be a member, use the
|
||||||
|
* WebDavResource(WebDavResource parent, URI url) constructor.
|
||||||
* @throws URISyntaxException
|
* @throws URISyntaxException
|
||||||
*/
|
*/
|
||||||
public WebDavResource(WebDavResource parent, String member) throws URISyntaxException {
|
public WebDavResource(WebDavResource parent, String member) throws URISyntaxException {
|
||||||
this(parent);
|
this(parent);
|
||||||
location = parent.location.resolve(URIUtils.parseURI(member, true));
|
location = parent.location.resolve(new URI(null, null, "./" + member, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebDavResource(WebDavResource parent, String member, String ETag) throws URISyntaxException {
|
public WebDavResource(WebDavResource parent, String member, String ETag) throws URISyntaxException {
|
||||||
|
Loading…
Reference in New Issue
Block a user