Fix XML querying bug

Fix #480
This commit is contained in:
Markus Unterwaditzer 2016-07-25 02:25:43 +02:00
parent 4df423b93e
commit 140af81ead
2 changed files with 30 additions and 1 deletions

View file

@ -0,0 +1,27 @@
from vdirsyncer.storage.dav import _parse_xml, _merge_xml
def test_xml_utilities():
x = _parse_xml('''<?xml version="1.0" encoding="UTF-8" ?>
<D:multistatus xmlns:D="DAV:">
<D:response>
<D:propstat>
<D:status>HTTP/1.1 404 Not Found</D:status>
<D:prop>
<D:getcontenttype/>
</D:prop>
</D:propstat>
<D:propstat>
<D:prop>
<D:resourcetype>
<D:collection/>
</D:resourcetype>
</D:prop>
</D:propstat>
</D:response>
</D:multistatus>
''')
response = x.find('{DAV:}response')
props = _merge_xml(response.findall('{DAV:}propstat/{DAV:}prop'))
assert props.find('{DAV:}resourcetype/{DAV:}collection') is not None
assert props.find('{DAV:}getcontenttype') is not None

View file

@ -79,7 +79,8 @@ def _parse_xml(content):
def _merge_xml(items):
rv = items[0]
rv.extend(items[1:])
for item in items[1:]:
rv.extend(item.getiterator())
return rv
@ -544,6 +545,7 @@ class DavStorage(Storage):
if not etag:
dav_logger.warning('Skipping {!r}, etag property is missing.'
.format(href))
continue
contenttype = getattr(props.find('{DAV:}getcontenttype'),
'text', None)