Hello everyone,

When the allowed priorities only span a single value, e.g.

(setopt org-priority-highest 1
        org-priority-lowest  1
        org-priority-default 1
        org-icalendar-include-todo t)

iCalendar export divides by zero when mapping them to the range 1–9,
which leads to an error e.g. ‘C-c C-e c f’
(‘org-icalendar-export-to-ics’) on

* TODO Task

I’ve attached a patch which maps these singleton ranges to the highest
priority (1).

Thanks,

-- 
Jacob S. Gordon
[email protected]
Please don’t send me HTML emails or MS Office/Apple iWork documents.
https://useplaintext.email/#etiquette
https://www.fsf.org/campaigns/opendocument
From c2e85a097311ba057728d9e6e8f586bc96b5a1b0 Mon Sep 17 00:00:00 2001
From: "Jacob S. Gordon" <[email protected]>
Date: Tue, 12 May 2026 16:20:00 -0400
Subject: [PATCH v1] ; ox-icalendar: Avoid overflow with singleton priority
 ranges

* lisp/ox-icalendar.el (org-icalendar--vtodo): Assign the highest
priority when the allowed range covers a single value.
* testing/lisp/test-ox-icalendar.el
(test-ox-icalendar/singleton-priorities): Add tests.
---
 lisp/ox-icalendar.el              |  8 +++++---
 testing/lisp/test-ox-icalendar.el | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/lisp/ox-icalendar.el b/lisp/ox-icalendar.el
index 9144a2958..272e3cf5d 100644
--- a/lisp/ox-icalendar.el
+++ b/lisp/ox-icalendar.el
@@ -1019,9 +1019,11 @@ (defun org-icalendar--vtodo
 	    (format "PRIORITY:%d\n"
 		    (let ((pri (or (org-element-property :priority entry)
 				   org-priority-default)))
-		      (floor (- 9 (* 8. (/ (float (- org-priority-lowest pri))
-					   (- org-priority-lowest
-					      org-priority-highest)))))))
+		      (if (= org-priority-lowest org-priority-highest)
+			  1
+			(floor (- 9 (* 8. (/ (float (- org-priority-lowest pri))
+					     (- org-priority-lowest
+						org-priority-highest))))))))
 	    (format "STATUS:%s\n"
 		    (if (eq (org-element-property :todo-type entry) 'todo)
 			"NEEDS-ACTION"
diff --git a/testing/lisp/test-ox-icalendar.el b/testing/lisp/test-ox-icalendar.el
index d2d518a9f..ef4df5ae8 100644
--- a/testing/lisp/test-ox-icalendar.el
+++ b/testing/lisp/test-ox-icalendar.el
@@ -267,5 +267,21 @@ (ert-deftest test-ox-icalendar/inline-task-keyword ()
             (should (not (search-forward "CONTACT:Jim Dolittle\, ABC Industries\, +1-919-555-1234" nil t 2)))))
       (when (file-exists-p tmp-ics) (delete-file tmp-ics)))))
 
+(ert-deftest test-ox-icalendar/singleton-priorities ()
+  "Test that exporting a range with a single priority doesn't overflow."
+  (dolist (p '(0 1 64 ?A ?Z))
+    (let* ((org-priority-highest p)
+           (org-priority-lowest p)
+           (org-priority-default p)
+           (org-icalendar-include-todo t)
+           (ics-file
+            (org-test-with-temp-text-in-file "* TODO Task"
+              (expand-file-name (org-icalendar-export-to-ics)))))
+      (with-temp-buffer
+        (insert-file-contents ics-file)
+        (should (search-forward "PRIORITY:1" nil t 1)))
+      (when (file-exists-p ics-file)
+        (delete-file ics-file)))))
+
 (provide 'test-ox-icalendar)
 ;;; test-ox-icalendar.el ends here

base-commit: fb9ebffa9fd900bdd68752a16c6dc493d665d336
-- 
Jacob S. Gordon
[email protected]
Please don’t send me HTML emails or MS Office/Apple iWork documents.
https://useplaintext.email/#etiquette
https://www.fsf.org/campaigns/opendocument

Reply via email to