fix: Escape CDATA special char on xblock serialize (#33239)

This fixes a bug in xblock serialization when trying to copy a
unit/component that contains an HTML xblock with the characters "]]>"
which is a special character in CDATA.
This commit is contained in:
Yusuf Musleh
2023-09-15 18:58:23 +03:00
committed by GitHub
parent ceb6628963
commit 0d15ca7240

View File

@@ -112,7 +112,10 @@ class XBlockSerializer:
olx_node.attrib["editor"] = block.editor
if block.use_latex_compiler:
olx_node.attrib["use_latex_compiler"] = "true"
olx_node.text = etree.CDATA("\n" + block.data + "\n")
# Escape any CDATA special chars
escaped_block_data = block.data.replace("]]>", "]]>")
olx_node.text = etree.CDATA("\n" + escaped_block_data + "\n")
return olx_node