diff --git a/tests/storage/dav/test_main.py b/tests/storage/dav/test_main.py index 7904ef5..196094b 100644 --- a/tests/storage/dav/test_main.py +++ b/tests/storage/dav/test_main.py @@ -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) diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py index fda9446..c4d66cb 100644 --- a/vdirsyncer/storage/dav.py +++ b/vdirsyncer/storage/dav.py @@ -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}")