lucc / khard

Console vcard client
https://khard.readthedocs.io/en/latest/
GNU General Public License v3.0
600 stars 65 forks source link

crash on specific string #249

Closed Tonus1 closed 4 years ago

Tonus1 commented 4 years ago

Hi,

Using khard with mutt (and without) gives me some strange behaviour :

$khard -c ~/.config/khard/khard.conf email ant
Traceback (most recent call last):
  File "/usr/bin/khard", line 11, in <module>
    load_entry_point('khard==0.16.1.dev3+ged5b451', 'console_scripts', 'khard')()
  File "/usr/lib64/python3.8/site-packages/khard/khard.py", line 1163, in main
    vcard_list = generate_contact_list(args)
  File "/usr/lib64/python3.8/site-packages/khard/khard.py", line 559, in generate_contact_list
    vcard_list = get_contact_list_by_user_selection(
  File "/usr/lib64/python3.8/site-packages/khard/khard.py", line 407, in get_contact_list_by_user_selection
    return get_contacts(address_books, search,
  File "/usr/lib64/python3.8/site-packages/khard/khard.py", line 448, in get_contacts
    return sorted(contacts, reverse=reverse, key=lambda x:
  File "/usr/lib64/python3.8/site-packages/khard/address_book.py", line 85, in _search_all
    and len(re.sub(r"\D", "", query)) >= 3:
  File "/usr/lib64/python3.8/re.py", line 208, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

This would not happen with longer string. For some specific, it works sometimes ("pap" gives results but "isa" fails, "pa" or cg fails and "is" gives results). I noticed the results are one per line, except sometimes (like with "is"), there's an empty line between each result.

Compiled from sources (git, release tarball would'nt work).

It seems that it's a strange bug shown with debug option : it fails because the searched string doesn't really exist in the vcard. I search ever and it fails with a card saying namephilippeverXXX but having First name "Philippe" and laste name "EverXXXsomething" without the real string in the vcard. Same fail with Jan Toxic while searching for "anto".

lucc commented 4 years ago

Thanks for the report @Tonus1. I have trouble reproducing this with the vcards in the test suite. Could you post your config file and provide a minimal vcard to reproduce this? Especially delete all sensitive information from the vcard.

Tonus1 commented 4 years ago

The vcard file :

$cat XXXXXXXXXabcd.vcf 
BEGIN:VCARD
VERSION:3.0
UID:c714939b-6646-465b-aae3-5edda32029cd
CATEGORIES:Famille
EMAIL;TYPE=internet:whatever@hotmail.fr
FN:Jan Tobis
N:Tobis;Jan;;;
REV:20200407T090133Z
END:VCARD

The khard.conf :

$cat khard.conf 
[addressbooks]
[[default]]
path = ~/Contacts/crash/
[general]
default_action = list
editor = nano
merge_editor = ~/.config/khard/sdiff_khard_wrapper.sh

[contact table]
# display names by first or last name: first_name / last_name
display = first_name
# group by address book: yes / no
#group_by_addressbook = yes
group_by_addressbook = no
# reverse table ordering: yes / no
reverse = no
# append nicknames to name column: yes / no
show_nicknames = no
# show uid table column: yes / no
show_uids = no
# sort by first or last name: first_name / last_name
sort = last_name
# localize dates: yes / no
localize_dates = yes
# set a comma separated list of preferred phone number types in descending priority
# or nothing for non-filtered alphabetical order
preferred_phone_number_type = pref,cell,work,home
# set a comma separated list of preferred email address types in descending priority
# or nothing for non-filtered alphabetical order
preferred_email_address_type = pref,work,home

[vcard]
# extend contacts with your own private objects
# these objects are stored with a leading "X-" before the object name in the vcard files
# every object label may only contain letters, digits and the - character
# example:
#   private_objects = Jabber, Skype, Twitter
#private_objects = Jabber, Skype, Twitter
# preferred vcard version: 3.0 / 4.0
#preferred_version = 4.0
preferred_version = 3.0
# Look into source vcf files to speed up search queries: yes / no
search_in_source_files = no
# skip unparsable vcard files: yes / no
skip_unparsable = yes

The request : khard -c khard.conf ls anto khard -c khard.conf email anto I could provide a few more, like Tonus Anja and request san or usanj, since the request could match the end of the first name and the beginning of the last name...

lucc commented 4 years ago

Thanks I can reproduce it with this. Can you test #250 and report back? If that works I think I can merge it tonight (have to go to work now).