mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
I think this makes sense
This commit is contained in:
parent
0650cc3bc2
commit
889183ec89
2 changed files with 16 additions and 13 deletions
|
|
@ -2,6 +2,7 @@ import pytest
|
||||||
|
|
||||||
from vdirsyncer.storage.dav import _BAD_XML_CHARS
|
from vdirsyncer.storage.dav import _BAD_XML_CHARS
|
||||||
from vdirsyncer.storage.dav import _merge_xml
|
from vdirsyncer.storage.dav import _merge_xml
|
||||||
|
from vdirsyncer.storage.dav import _normalize_href
|
||||||
from vdirsyncer.storage.dav import _parse_xml
|
from vdirsyncer.storage.dav import _parse_xml
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,3 +45,13 @@ def test_xml_specialchars(char):
|
||||||
|
|
||||||
if char in _BAD_XML_CHARS:
|
if char in _BAD_XML_CHARS:
|
||||||
assert x.text == "yes\nhello"
|
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)
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,7 @@ async def _assert_multistatus_success(r):
|
||||||
|
|
||||||
|
|
||||||
def _normalize_href(base, href):
|
def _normalize_href(base, href):
|
||||||
"""Normalize the href to be a path only relative to hostname and
|
"""Normalize the href to be a path only relative to hostname and schema."""
|
||||||
schema."""
|
|
||||||
orig_href = href
|
orig_href = href
|
||||||
if not href:
|
if not href:
|
||||||
raise ValueError(href)
|
raise ValueError(href)
|
||||||
|
|
@ -74,17 +73,10 @@ def _normalize_href(base, href):
|
||||||
x = urlparse.urljoin(base, href)
|
x = urlparse.urljoin(base, href)
|
||||||
x = urlparse.urlsplit(x).path
|
x = urlparse.urlsplit(x).path
|
||||||
|
|
||||||
# Encoding issues:
|
# We unquote and quote again, but want to make sure we
|
||||||
# - https://github.com/owncloud/contacts/issues/581
|
# keep around the "@" character.
|
||||||
# - 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.unquote(x)
|
||||||
|
x = urlparse.quote(x, "/@")
|
||||||
x = urlparse.quote(x, "/@%:")
|
|
||||||
|
|
||||||
if orig_href == x:
|
if orig_href == x:
|
||||||
dav_logger.debug(f"Already normalized: {x!r}")
|
dav_logger.debug(f"Already normalized: {x!r}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue