all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#56241: [PATCH] icalendar doesn't correctly process arbitrary diary sexp entries
@ 2022-06-26 18:36 hokomo
  2022-06-27  8:04 ` Lars Ingebrigtsen
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: hokomo @ 2022-06-26 18:36 UTC (permalink / raw)
  To: 56241

[-- 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-01-28 17:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-26 18:36 bug#56241: [PATCH] icalendar doesn't correctly process arbitrary diary sexp entries hokomo
2022-06-27  8:04 ` 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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.