Bug 238543 - www/pycarddav: Syncing a contact with UTF-8 characters fails
Summary: www/pycarddav: Syncing a contact with UTF-8 characters fails
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-ports-bugs mailing list
URL:
Keywords: needs-patch, needs-qa
Depends on:
Blocks:
 
Reported: 2019-06-13 09:24 UTC by Oliver Adler
Modified: 2019-07-11 03:18 UTC (History)
3 users (show)

See Also:
koobs: maintainer-feedback+
koobs: merge-quarterly?


Attachments
Instead of unconditionally returning unicode, i check for the used charset with chardet.detect() (1.44 KB, text/plain)
2019-06-13 09:24 UTC, Oliver Adler
no flags Details
svn diff to include Oliver's patch in the port (2.37 KB, patch)
2019-06-25 05:27 UTC, samir
samir: maintainer-approval+
Details | Diff
svn diff to include patch from Github (1.50 KB, patch)
2019-07-11 03:18 UTC, samir
samir: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Adler 2019-06-13 09:24:07 UTC
Created attachment 205028 [details]
Instead of unconditionally returning unicode, i check for the used charset with chardet.detect()

During syncing with an owncloud instance with the command:
$ pycardsyncer 
one gets the following error, in case utf8 characters like Ä (German umlaut A) are included in a contact there will show the following crash:

Traceback (most recent call last):
  File "/usr/local/bin/pycardsyncer", line 55, in <module>
    sync(conf)
  File "/usr/local/lib/python2.7/site-packages/pycarddav/controllers/sync.py", line 57, in sync
    my_dbtool.update(vcard, conf.account.name, href=href, etag=etag)
  File "/usr/local/lib/python2.7/site-packages/pycarddav/backend.py", line 272, in update
    stuple = (etag, vcard.name, vcard.fname, vcard_s, status, href, href)
  File "/usr/local/lib/python2.7/site-packages/pycarddav/model.py", line 201, in name
    return unicode(self['N'][0][0]) if self['N'] else ''
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)

I assume, that the error is not owncloud specific. It is only necessary to have a changed contact
with an utf8 character in the Name.

I could fix the problem and the patch is in the appendix.
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2019-06-13 13:28:34 UTC
Thank you for the report and patch Oliver.

This looks like a good candidate to report (or PR) upstream, but having said that, this looks like upstream issue: https://github.com/geier/pycarddav/issues/127 

There are two relevant (open) PR's:

https://github.com/geier/pycarddav/pull/124 (Nov 2018)
https://github.com/geier/pycarddav/pull/128 (Apr 2016)

The PR's have not been merged and the issue has not been closed. On that note, upstream has the following repository note:

DEPRECATED - use vdirsyncer & khard 

And in the README:

This project is dead
pyCardDAV is deprecated. See the relevant issue. A good alternative is khard.

We should add DEPRECATED to this port with an EXPIRY_DATE, whether or not we resolve this specific issue with a ports-local patch

[1] https://github.com/ph1l/pycarddav/commit/662923657f2345fda67fbbc1a7863a5d3b6ba58a
Comment 2 samir 2019-06-25 05:27:41 UTC
Created attachment 205321 [details]
svn diff to include Oliver's patch in the port
Comment 3 samir 2019-06-25 05:29:47 UTC
I have the problem when I test by adding a contact with UTF-8 in the name in Nextcloud. Oliver's patch work well.

PR #220368 is related to the deprecating problem. The port removal with DEPRECATED and EXPIRATION_DATE could provide a message to propose desktuils/py-khard as a replacement. 

How longtime is acceptable to put in the EXPIRATION_DATE ?

I've added a diff in attachment to include Oliver's patch in the port.
Comment 4 Kubilay Kocak freebsd_committer freebsd_triage 2019-06-25 05:42:51 UTC
Thank you Samir, could you please set maintainer-approval flag to + on the attachment/patch please
Comment 5 samir 2019-06-26 00:22:38 UTC
I've putted the flag
Comment 6 Kubilay Kocak freebsd_committer freebsd_triage 2019-07-01 15:19:00 UTC
I just checked the upstream issue, and I'd probably take the pull request that fixes the issue:

https://github.com/geier/pycarddav/pull/128

@Samir Could you produce a patch adding this PR

@Oliver Could you test that patch once its produced to confirm it resolves the issue
Comment 7 samir 2019-07-11 03:18:35 UTC
Created attachment 205686 [details]
svn diff to include patch from Github

The patch in attachment, with the correction from Github. But when I try to use pc_query I have the following error :
 
   UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 12: ordinal not in range(128)

Which I don't have with Oliver patch