I think this makes sense

This commit is contained in:
Hugo Osvaldo Barrera 2021-07-25 13:25:16 +02:00
parent 0650cc3bc2
commit 889183ec89
2 changed files with 16 additions and 13 deletions

View file

@ -2,6 +2,7 @@ import pytest
from vdirsyncer.storage.dav import _BAD_XML_CHARS
from vdirsyncer.storage.dav import _merge_xml
from vdirsyncer.storage.dav import _normalize_href
from vdirsyncer.storage.dav import _parse_xml
@ -44,3 +45,13 @@ def test_xml_specialchars(char):
if char in _BAD_XML_CHARS:
assert x.text == "yes\nhello"
@pytest.mark.parametrize(
"href",
[
"/dav/calendars/user/testuser/123/UID%253A20210609T084907Z-@synaps-web-54fddfdf7-7kcfm%250A.ics", # noqa: E501
],
)
def test_normalize_href(href):
assert href == _normalize_href("https://example.com", href)

View file

@ -65,8 +65,7 @@ async def _assert_multistatus_success(r):
def _normalize_href(base, href):
"""Normalize the href to be a path only relative to hostname and
schema."""
"""Normalize the href to be a path only relative to hostname and schema."""
orig_href = href
if not href:
raise ValueError(href)
@ -74,17 +73,10 @@ def _normalize_href(base, href):
x = urlparse.urljoin(base, href)
x = urlparse.urlsplit(x).path
# Encoding issues:
# - https://github.com/owncloud/contacts/issues/581
# - https://github.com/Kozea/Radicale/issues/298
old_x = None
while old_x is None or x != old_x:
if _contains_quoted_reserved_chars(x):
break
old_x = x
x = urlparse.unquote(x)
x = urlparse.quote(x, "/@%:")
# We unquote and quote again, but want to make sure we
# keep around the "@" character.
x = urlparse.unquote(x)
x = urlparse.quote(x, "/@")
if orig_href == x:
dav_logger.debug(f"Already normalized: {x!r}")