fix(contacts): address PR #876 round-1 review

- Use str.removesuffix(".vcf") instead of str.replace(".vcf", "") in both
  _resolve_object_name and list_contacts so a filename like "alice.vcf.backup"
  isn't mangled; the two transforms stay consistent to preserve the
  surface-then-resolve round-trip.
- Add update_contact resolution tests mirroring the delete coverage:
  targets the real no-extension path, and falls back to <uid>.vcf when
  resolution finds nothing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-08 01:47:46 +02:00
co-authored by Claude Opus 4.8
parent 854ef349cd
commit 011356cca2
2 changed files with 54 additions and 3 deletions
+5 -3
View File
@@ -258,7 +258,7 @@ class ContactsClient(BaseNextcloudClient):
async def _resolve_object_name(self, addressbook: str, uid: str) -> str | None:
"""Map a surfaced contact id back to its real CardDAV object filename.
``list_contacts`` surfaces ``vcard_id`` with any ``.vcf`` suffix
``list_contacts`` surfaces ``vcard_id`` with a trailing ``.vcf`` suffix
stripped, so reverse that transform here: return the object whose
filename reduces to ``uid``. The conventional ``<uid>.vcf`` is
preferred when present (deterministic for the common case), otherwise
@@ -267,7 +267,7 @@ class ContactsClient(BaseNextcloudClient):
candidates = [
name
for name in await self._list_object_names(addressbook)
if name.replace(".vcf", "") == uid
if name.removesuffix(".vcf") == uid
]
if not candidates:
return None
@@ -512,7 +512,9 @@ class ContactsClient(BaseNextcloudClient):
continue
# ``vcard_id`` keeps the historical ``.vcf``-stripped form for
# backward compatibility with callers that use it as the contact id.
vcard_id = object_name.replace(".vcf", "")
# Must use the same trailing-suffix strip as ``_resolve_object_name``
# so the surface-then-resolve round-trip stays lossless (issue #874).
vcard_id = object_name.removesuffix(".vcf")
# Get properties
propstat = response_elem.find(".//d:propstat", ns)