From 89063c5096ecf501a6268a20bdffe30b432e8ab3 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 11 May 2014 21:54:57 +0200 Subject: [PATCH 1/2] Add test case for #49 --- tests/storage/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py index a629a32..ba0e5fb 100644 --- a/tests/storage/__init__.py +++ b/tests/storage/__init__.py @@ -22,6 +22,7 @@ class StorageTests(object): def _create_bogus_item(self, uid, item_template=None): r = random.random() item_template = item_template or self.item_template + uid = '{}@vdirsyncer_tests'.format(uid) return Item(item_template.format(uid=uid, r=r)) def get_storage_args(self, collection=None): @@ -34,8 +35,6 @@ class StorageTests(object): def test_generic(self): items = map(self._create_bogus_item, range(1, 10)) - for i, item in enumerate(items): - assert item.uid == text_type(i + 1), item.raw s = self._get_storage() hrefs = [] for item in items: From b5df8a45146af2e18fa1073c0d74e151b3c8f170 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Mon, 12 May 2014 18:54:04 +0200 Subject: [PATCH 2/2] Possible fix for #49 - Radicale incorrectly unquotes URLs - Older versions of radicale are so buggy they fail to look up items with url quotes in them. - ownCloud/SabreDAV follows the rebustness principle such that it takes anything, but returns properly encoded URLs. Conclusion: Send broken, unquoted URLs, because both sides seem to be happy with them. As wrong as it might seem, it works. --- vdirsyncer/storage/dav.py | 3 ++- vdirsyncer/utils.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py index 4715a21..bf2e5ed 100644 --- a/vdirsyncer/storage/dav.py +++ b/vdirsyncer/storage/dav.py @@ -117,9 +117,10 @@ class DavStorage(Storage): schema.''' x = utils.urlparse.urljoin(self.url, href) assert x.startswith(self.url) - return utils.urlparse.urlsplit(x).path + return utils.urlunquote_plus(utils.urlparse.urlsplit(x).path) def _get_href(self, uid): + uid = utils.urlunquote_plus(uid) return self._normalize_href(super(DavStorage, self)._get_href(uid)) def _request(self, method, path, data=None, headers=None): diff --git a/vdirsyncer/utils.py b/vdirsyncer/utils.py index 505ea0b..ffea748 100644 --- a/vdirsyncer/utils.py +++ b/vdirsyncer/utils.py @@ -22,11 +22,16 @@ PY2 = sys.version_info[0] == 2 if PY2: import urlparse + from urllib import \ + quote_plus as urlquote_plus, \ + unquote_plus as urlunquote_plus text_type = unicode # flake8: noqa iteritems = lambda x: x.iteritems() itervalues = lambda x: x.itervalues() else: import urllib.parse as urlparse + urlquote_plus = urlparse.quote_plus + urlunquote_plus = urlparse.unquote_plus text_type = str iteritems = lambda x: x.items() itervalues = lambda x: x.values()