fix(webdav): decode percent-encoded names in PROPFIND/SEARCH responses

`<d:href>` is required by RFC 3986 to be percent-encoded, so non-ASCII
filenames (e.g. Chinese, Cyrillic) were leaking through `list_directory`
and the SEARCH-based tools (`find_by_name`, `find_by_type`,
`list_favorites`, `search_files`) as their URL-encoded form. Decode with
the already-imported `urllib.parse.unquote` before exposing to callers.

Fixes #776

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-05-09 12:57:58 +02:00
co-authored by Claude Opus 4.7
parent fcc8dab6f6
commit 928b973eb8
2 changed files with 104 additions and 4 deletions
+8 -4
View File
@@ -257,9 +257,11 @@ class WebDAVClient(BaseNextcloudClient):
if href is None:
continue
# Extract file/directory name from href
# Extract file/directory name from href. <d:href> is required by
# RFC 3986 to be percent-encoded, so non-ASCII names arrive
# encoded — decode before exposing to callers (issue #776).
href_text = href.text or ""
name = href_text.rstrip("/").split("/")[-1]
name = unquote(href_text.rstrip("/").split("/")[-1])
if not name:
continue
@@ -767,8 +769,10 @@ class WebDAVClient(BaseNextcloudClient):
if href is None:
continue
# Extract file/directory path from href
href_text = href.text or ""
# Extract file/directory path from href. <d:href> is required by
# RFC 3986 to be percent-encoded, so non-ASCII paths arrive
# encoded — decode before exposing to callers (issue #776).
href_text = unquote(href.text or "")
# Remove the /remote.php/dav/files/username/ prefix to get relative path
path_parts = href_text.split("/files/")
if len(path_parts) > 1: