From a980541c7300001181a25c2ed80401766d3abcaa Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 6 Feb 2026 10:15:08 -0600 Subject: fix(calendar-sync): sanitize description text to prevent org heading corruption Event descriptions containing lines starting with * were being interpreted as org headings, breaking file structure. Replace leading asterisks with dashes before writing descriptions. --- modules/calendar-sync.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/calendar-sync.el b/modules/calendar-sync.el index 06248531..022aff80 100644 --- a/modules/calendar-sync.el +++ b/modules/calendar-sync.el @@ -275,6 +275,17 @@ Returns nil for nil input. Returns empty string for whitespace-only input." (when text (string-trim (calendar-sync--strip-html (calendar-sync--unescape-ics-text text))))) +(defun calendar-sync--sanitize-org-body (text) + "Sanitize TEXT for safe inclusion as org body content. +Replaces leading asterisks with dashes to prevent lines from being +parsed as org headings. Handles multiple levels (e.g. ** becomes --)." + (when text + (replace-regexp-in-string + "^\\(\\*+\\) " + (lambda (match) + (concat (make-string (length (match-string 1 match)) ?-) " ")) + text))) + ;;; Date Utilities (defun calendar-sync--add-months (date months) @@ -1175,9 +1186,9 @@ Description appears as body text after the drawer." (dolist (prop props) (push prop parts)) (push ":END:" parts)) - ;; Add description as body text + ;; Add description as body text (sanitized to prevent org heading conflicts) (when (and description (not (string-empty-p description))) - (push description parts)) + (push (calendar-sync--sanitize-org-body description) parts)) (string-join (nreverse parts) "\n")))) (defun calendar-sync--event-start-time (event) -- cgit v1.2.3