Fix crash in google calendar when using filters

Fix #657
This commit is contained in:
Markus Unterwaditzer 2017-08-15 14:04:39 +02:00
parent c9a085522f
commit 35ffdd6f8c
2 changed files with 14 additions and 5 deletions

View file

@ -9,6 +9,12 @@ Package maintainers and users who have to manually update their installation
may want to subscribe to `GitHub's tag feed may want to subscribe to `GitHub's tag feed
<https://github.com/pimutils/vdirsyncer/tags.atom>`_. <https://github.com/pimutils/vdirsyncer/tags.atom>`_.
Version 0.16.2
==============
- Fix crash when using daterange or item_type filters in
:storage:`google_calendar`, see :gh:`657`.
Version 0.16.1 Version 0.16.1
============== ==============

View file

@ -558,8 +558,9 @@ class DAVStorage(Storage):
headers=headers headers=headers
) )
def _parse_prop_responses(self, root): def _parse_prop_responses(self, root, handled_hrefs=None):
hrefs = set() if handled_hrefs is None:
handled_hrefs = set()
for response in root.iter('{DAV:}response'): for response in root.iter('{DAV:}response'):
href = response.find('{DAV:}href') href = response.find('{DAV:}href')
if href is None: if href is None:
@ -568,7 +569,7 @@ class DAVStorage(Storage):
href = self._normalize_href(href.text) href = self._normalize_href(href.text)
if href in hrefs: if href in handled_hrefs:
# Servers that send duplicate hrefs: # Servers that send duplicate hrefs:
# - Zimbra # - Zimbra
# https://github.com/pimutils/vdirsyncer/issues/88 # https://github.com/pimutils/vdirsyncer/issues/88
@ -604,7 +605,7 @@ class DAVStorage(Storage):
self.item_mimetype)) self.item_mimetype))
continue continue
hrefs.add(href) handled_hrefs.add(href)
yield href, etag, props yield href, etag, props
def list(self): def list(self):
@ -838,12 +839,14 @@ class CalDAVStorage(DAVStorage):
# the spec which values from WebDAV are actually allowed. # the spec which values from WebDAV are actually allowed.
headers['Depth'] = '1' headers['Depth'] = '1'
handled_hrefs = set()
for caldavfilter in caldavfilters: for caldavfilter in caldavfilters:
xml = data.format(caldavfilter=caldavfilter).encode('utf-8') xml = data.format(caldavfilter=caldavfilter).encode('utf-8')
response = self.session.request('REPORT', '', data=xml, response = self.session.request('REPORT', '', data=xml,
headers=headers) headers=headers)
root = _parse_xml(response.content) root = _parse_xml(response.content)
rv = self._parse_prop_responses(root) rv = self._parse_prop_responses(root, handled_hrefs)
for href, etag, _prop in rv: for href, etag, _prop in rv:
yield href, etag yield href, etag