From f6352e497c5aebb8faabe176c6b22f592d451be6 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 10 Sep 2026 06:23:32 +0000 Subject: [PATCH] Text.Pandoc.XML.Light: fix escaping of repeated ]]> in CDATA. escCData stopped processing after the first "]]>" occurrence, emitting the rest of the text verbatim; a second "]]>" would prematurely terminate the CDATA section, producing invalid XML. (The original xml-light code recurses after each occurrence; the recursion was lost in the Text port.) Rewritten with T.breakOn, which also avoids building the output one character at a time. Co-Authored-By: Claude --- xml-light/Text/Pandoc/XML/Light/Output.hs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/xml-light/Text/Pandoc/XML/Light/Output.hs b/xml-light/Text/Pandoc/XML/Light/Output.hs index 0caba6899..a2975ae35 100644 --- a/xml-light/Text/Pandoc/XML/Light/Output.hs +++ b/xml-light/Text/Pandoc/XML/Light/Output.hs @@ -173,13 +173,12 @@ showCDataS cd = -------------------------------------------------------------------------------- escCData :: Text -> Builder -escCData t - | "]]>" `T.isPrefixOf` t = - fromText "]]]]>" <> fromText (T.drop 3 t) -escCData t - = case T.uncons t of - Nothing -> mempty - Just (c,t') -> singleton c <> escCData t' +escCData t = + case T.breakOn "]]>" t of + (chunk, rest) + | T.null rest -> fromText chunk + | otherwise -> fromText chunk <> fromText "]]]]>" <> + escCData (T.drop 3 rest) escChar :: Char -> Builder escChar c = case c of