diff options
| author | Craig Jennings <c@cjennings.net> | 2026-02-06 10:15:08 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-02-06 10:15:08 -0600 |
| commit | a980541c7300001181a25c2ed80401766d3abcaa (patch) | |
| tree | 1418a96c09172efb9d7b8b8c79bf483f38000326 /modules | |
| parent | 00ddf74b232b0762baa7826e62f6765d087041fb (diff) | |
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.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/calendar-sync.el | 15 |
1 files changed, 13 insertions, 2 deletions
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) |
