1
0
mirror of https://github.com/etesync/android synced 2024-11-25 17:38:13 +00:00

Handle resources with "%" and other special characters in file name more accurately (fixes #401)

This commit is contained in:
R Hirner 2014-12-27 22:41:23 +01:00
parent 0423e00ffd
commit 6f5748c464
7 changed files with 22 additions and 10 deletions

View File

@ -13,7 +13,7 @@ Twitter: [@davdroidapp](https://twitter.com/davdroidapp)
USED THIRD-PARTY LIBRARIES USED THIRD-PARTY LIBRARIES
========================== ==========================
* [Apache HttpClient](http://hc.apache.org) ([httpclientandroidlib](https://code.google.com/p/httpclientandroidlib/) flavour) [Apache License](http://www.apache.org/licenses/) * [Apache HttpClient](http://hc.apache.org) (Android port) [Apache License](http://www.apache.org/licenses/)
* [iCal4j](http://ical4j.sourceforge.net/) [New BSD License](http://sourceforge.net/p/ical4j/ical4j/ci/default/tree/LICENSE) * [iCal4j](http://ical4j.sourceforge.net/) [New BSD License](http://sourceforge.net/p/ical4j/ical4j/ci/default/tree/LICENSE)
* [ez-vcard](https://code.google.com/p/ez-vcard/) [New BSD License](http://opensource.org/licenses/BSD-3-Clause) * [ez-vcard](https://code.google.com/p/ez-vcard/) [New BSD License](http://opensource.org/licenses/BSD-3-Clause)
* [Simple XML Serialization](http://simple.sourceforge.net/) [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) * [Simple XML Serialization](http://simple.sourceforge.net/) [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)

View File

@ -12,6 +12,7 @@ android {
buildTypes { buildTypes {
debug { debug {
minifyEnabled false
} }
release { release {
minifyEnabled true minifyEnabled true

View File

@ -170,10 +170,16 @@ public class WebDavResourceTest extends InstrumentationTestCase {
} }
public void testMultiGet() throws Exception { public void testMultiGet() throws Exception {
WebDavResource davAddressBook = new WebDavResource(davCollection, "addressbooks/default.vcf"); WebDavResource davAddressBook = new WebDavResource(davCollection, "addressbooks/default.vcf/");
davAddressBook.multiGet(DavMultiget.Type.ADDRESS_BOOK, new String[] { "1.vcf", "2.vcf" }); davAddressBook.multiGet(DavMultiget.Type.ADDRESS_BOOK, new String[] { "1.vcf", "2:3@my%40pc.vcf" });
// queried address book has a name
assertEquals("My Book", davAddressBook.getDisplayName()); assertEquals("My Book", davAddressBook.getDisplayName());
// there are two contacts
assertEquals(2, davAddressBook.getMembers().size()); assertEquals(2, davAddressBook.getMembers().size());
// contact file names should be unescaped (yes, it's really named ...%40pc... to check double-encoding)
assertEquals("1.vcf", davAddressBook.getMembers().get(0).getName());
assertEquals("2:3@my%40pc.vcf", davAddressBook.getMembers().get(1).getName());
// both contacts have content
for (WebDavResource member : davAddressBook.getMembers()) for (WebDavResource member : davAddressBook.getMembers())
assertNotNull(member.getContent()); assertNotNull(member.getContent());
} }

View File

@ -224,14 +224,16 @@ exports.getBodyParts = function(conf) {
new RoboHydraHeadDAV({ new RoboHydraHeadDAV({
path: "/dav/addressbooks/default.vcf/", path: "/dav/addressbooks/default.vcf/",
handler: function(req,res,next) { handler: function(req,res,next) {
if (req.method == "REPORT" && req.rawBody.toString().match(/addressbook-multiget[\s\S]+<prop>[\s\S]+<href>/m)) { if (req.method == "REPORT" && req.rawBody.toString().match(/addressbook-multiget[\s\S]+<prop>[\s\S]+<href>/m &&
req.rawBody.toString().match(/<href>\/dav\/addressbooks\/default\.vcf\/2:3@my%2540pc\.vcf<\/href>/m))) {
res.statusCode = 207; res.statusCode = 207;
res.write('\<?xml version="1.0" encoding="utf-8" ?>\ res.write('\<?xml version="1.0" encoding="utf-8" ?>\
<multistatus xmlns="DAV:" xmlns:CARD="urn:ietf:params:xml:ns:carddav">\ <multistatus xmlns="DAV:" xmlns:CARD="urn:ietf:params:xml:ns:carddav">\
<response>\ <response>\
<href>/dav/addressbooks/d%65fault.vcf</href>\ <href>/dav/addressbooks/default.vcf</href>\
<propstat>\ <propstat>\
<prop>\ <prop>\
<resourcetype><collection/></resourcetype>\
<displayname>My Book</displayname>\ <displayname>My Book</displayname>\
</prop>\ </prop>\
<status>HTTP/1.1 200 OK</status>\ <status>HTTP/1.1 200 OK</status>\
@ -253,7 +255,7 @@ exports.getBodyParts = function(conf) {
</propstat>\ </propstat>\
</response>\ </response>\
<response>\ <response>\
<href>/dav/addressbooks/default.vcf/2.vcf</href>\ <href>/dav/addressbooks/default.vcf/2:3%40my%2540pc.vcf</href>\
<propstat>\ <propstat>\
<prop>\ <prop>\
<getetag/>\ <getetag/>\

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.bitfire.davdroid" package="at.bitfire.davdroid"
android:versionCode="49" android:versionCode="50"
android:versionName="0.6.9.1" android:installLocation="internalOnly"> android:versionName="0.6.9.2" android:installLocation="internalOnly">
<uses-sdk <uses-sdk
android:minSdkVersion="14" android:minSdkVersion="14"

View File

@ -9,7 +9,7 @@ package at.bitfire.davdroid;
public class Constants { public class Constants {
public static final String public static final String
APP_VERSION = "0.6.9.1", APP_VERSION = "0.6.9.2",
ACCOUNT_TYPE = "bitfire.at.davdroid", ACCOUNT_TYPE = "bitfire.at.davdroid",
WEB_URL_HELP = "https://davdroid.bitfire.at/configuration?pk_campaign=davdroid-app"; WEB_URL_HELP = "https://davdroid.bitfire.at/configuration?pk_campaign=davdroid-app";
} }

View File

@ -296,7 +296,10 @@ public class WebDavResource {
// build multi-get XML request // build multi-get XML request
List<String> hrefs = new LinkedList<String>(); List<String> hrefs = new LinkedList<String>();
for (String name : names) for (String name : names)
hrefs.add(location.resolve(name).getPath()); // name may contain "%" which have to be encoded use non-quoting URI constructor and getRawPath()
// name may also contain ":", so prepend "./" because even the non-quoting URI constructor parses after constructing
// DAVdroid ensures that collections always have a trailing slash, so "./" won't go down in directory hierarchy
hrefs.add(location.resolve(new URI(null, null, "./" + name, null)).getRawPath());
DavMultiget multiget = DavMultiget.newRequest(type, hrefs.toArray(new String[0])); DavMultiget multiget = DavMultiget.newRequest(type, hrefs.toArray(new String[0]));
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();