unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: hokomo <hokomo@airmail.cc>
To: 56241@debbugs.gnu.org
Subject: bug#56241: [PATCH] icalendar doesn't correctly process arbitrary diary sexp entries
Date: Sun, 26 Jun 2022 20:36:46 +0200	[thread overview]
Message-ID: <21bff87f-b8dc-c7bc-41ab-97c7077a0535@airmail.cc> (raw)

[-- Attachment #1: Type: text/plain, Size: 1891 bytes --]

icalendar is capable of exporting arbitrary diary sexp entries, but it 
looks like there's a bug in the code. Each conversion function 
`icalendar--convert-*-to-ical' can return either a dotted pair or a list 
of such pairs, but the code fails to differentiate the two cases properly.

To reproduce:

(require 'icalendar)

(defun test-diary-sexp (sexp)
   (message "Testing %S\n" sexp)
   (let ((file (make-temp-file "export.ics")))
     (with-temp-buffer
       (insert sexp)
       (icalendar-export-region (point-min) (point-max) file))
     (with-current-buffer (get-buffer "*icalendar-errors*")
       (message "export: %S\n" (with-temp-buffer
                             (insert-file-contents file)
                             (buffer-string)))
       (message "errors: %S" (buffer-string))))
   (terpri))

(defun my-float (&rest args)
   (apply #'diary-float args))

(let ((icalendar-export-sexp-enumeration-days 366))
   (test-diary-sexp "%%(diary-float 7 0 1) First Sunday in July 1")
   (test-diary-sexp "%%(my-float 7 0 1) First Sunday in July 2"))

Exporting the my-float sexp will fail with:

"Error in line 0 -- (wrong-type-argument listp First Sunday in July 2): 
‘%%(my-float 7 0 1) First Sunday in July 2"

because the returned list is confused for a dotted pair.

`icalendar-export-sexp-enumeration-days' is set to 366 to guarantee that 
the sexp event occurs at least once. It looks like there's a different 
bug (?) where, even if an entry is recognized as an arbitrary diary 
sexp, if it doesn't produce any events, the converter will go ahead with 
trying to interpret it in a different way and eventually fail. E.g., 
lowering the enumeration days to 0 gives:

"Error in line 0 -- (error Could not parse date): ‘%%(my-float 7 0 1) 
First Sunday in July 2’"

after exhausting all of the known entry types. Should I file this as a 
separate bug?

Regards,
hokomo

[-- Attachment #2: 0001-Fix-detecting-dotted-pairs.patch --]
[-- Type: text/x-patch, Size: 1083 bytes --]

From 691f34a301359893bcffff8e4e0c8794a1fd5e68 Mon Sep 17 00:00:00 2001
From: hokomo <hokomo@airmail.cc>
Date: Sat, 25 Jun 2022 09:44:54 +0200
Subject: [PATCH] Fix detecting dotted pairs

* lisp/calendar/icalendar.el (icalendar-export-region): Fix detecting
dotted pairs.
---
 lisp/calendar/icalendar.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el
index 1a5a071e20..cf54293989 100644
--- a/lisp/calendar/icalendar.el
+++ b/lisp/calendar/icalendar.el
@@ -1144,7 +1144,8 @@ icalendar-export-region
                                      (cdr contents-n-summary))))
                       (setq result (concat result header contents alarm
                                            "\nEND:VEVENT")))
-                    (if (consp cns-cons-or-list)
+                    (if (and (consp cns-cons-or-list)
+                             (not (listp (cdr cns-cons-or-list))))
                         (list cns-cons-or-list)
                       cns-cons-or-list)))
           ;; handle errors
-- 
2.35.3


             reply	other threads:[~2022-06-26 18:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-26 18:36 hokomo [this message]
2022-06-27  8:04 ` bug#56241: [PATCH] icalendar doesn't correctly process arbitrary diary sexp entries Lars Ingebrigtsen
2022-06-27  9:42   ` hokomo
2022-06-28 11:21     ` Lars Ingebrigtsen
2022-07-06 18:58       ` hokomo
2022-07-07  8:08         ` Lars Ingebrigtsen
2022-07-24 18:14       ` Ulf Jasper
2022-11-11 13:38         ` Stefan Kangas
2022-11-23 20:24           ` Ulf Jasper
2022-11-24 18:07             ` Ulf Jasper
2023-07-04 10:29             ` Brendan O'Dea
2023-07-04 14:20 ` Mattias Engdegård
2023-07-07 13:15   ` Mattias Engdegård
2024-01-28 17:09 ` Jeremy Harrison via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21bff87f-b8dc-c7bc-41ab-97c7077a0535@airmail.cc \
    --to=hokomo@airmail.cc \
    --cc=56241@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).