pinoaffe / org-vcard

Export and import vCards from within GNU Emacs' Org mode.
61 stars 7 forks source link

fix error when card has no heading (FN or N) #33

Closed dalanicolai closed 3 years ago

dalanicolai commented 3 years ago

Currently, when a vcard has no heading (which can happen e.g. when exporting from 'google contacts'), the importer crashes with the following message:

Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
replace-regexp-in-string("^;\\|;$" "" nil)

etc.

This PR fixes the issue and gives the vcard without heading, a "NO TITLE" heading in the .org file

flexibeast commented 3 years ago

Thanks for your contribution!

It's been over six years since i last worked on that code, so i'm not sure why the call to replace-regex-in-string is there, but i have to assume it was necessary for data cleaning in a particular case. Given that, i'd like to instead have:

(setq heading
      (or (cdr (assoc org-vcard-default-property-for-heading card))
          (let ((value (cdr
                        (assoc
                         (if (string=
                              org-vcard-default-property-for-heading
                              "FN")
                             "N"
                           "FN") card))))
            (if value
                (replace-regexp-in-string "^;\\|;$" "" value)
              "NO TITLE"))))

Does the above code work for your use-case?

dalanicolai commented 3 years ago

Ah yes I see. Your new code works fine here indeed. :+1:

flexibeast commented 3 years ago

Fixed in https://github.com/flexibeast/org-vcard/commit/f4b7445550deb30e170a25fc42541e99730e21d0, closing.

Thanks again!