From a1f31042e0c7513714bcb0d51347168d6a65210a Mon Sep 17 00:00:00 2001 From: Paolo Donadeo Date: Sun, 17 May 2026 13:25:19 +0200 Subject: [PATCH] feat(remind): escape special characters in MSG clause body --- bin/remind.ml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/remind.ml b/bin/remind.ml index 576f008..8b78a9e 100644 --- a/bin/remind.ml +++ b/bin/remind.ml @@ -121,7 +121,20 @@ let add_through b = function | Some d -> Buffer.add_string b (spf " THROUGH %s" (Timedesc.Date.to_rfc3339 d)) | None -> () -let add_msg b summary = Buffer.add_string b (spf " MSG %s\n" summary) +(** Escape special characters in the body of a MSG clause. + - '%' must become '%%' (literal percent) + - '[' must become '["["]' (a Remind expression that evaluates to the literal string "[") *) +let escape_msg s = + let buf = Buffer.create (String.length s) in + String.iter + (function + | '%' -> Buffer.add_string buf "%%" + | '[' -> Buffer.add_string buf {|["["]|} + | c -> Buffer.add_char buf c) + s; + Buffer.contents buf + +let add_msg b summary = Buffer.add_string b (spf " MSG %s\n" (escape_msg summary)) let date_of_date_or_datetime (d : Icalendar.date_or_datetime) : Timedesc.Date.t = match d with