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 <noreply@anthropic.com>
This commit is contained in:
John MacFarlane
2026-09-09 23:30:32 -07:00
co-authored by Claude
parent ef442564af
commit f6352e497c
+6 -7
View File
@@ -173,13 +173,12 @@ showCDataS cd =
--------------------------------------------------------------------------------
escCData :: Text -> Builder
escCData t
| "]]>" `T.isPrefixOf` t =
fromText "]]]]><![CDATA[>" <> 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 "]]]]><![CDATA[>" <>
escCData (T.drop 3 rest)
escChar :: Char -> Builder
escChar c = case c of