diff --git a/openedx/core/djangoapps/content_staging/tests/test_clipboard.py b/openedx/core/djangoapps/content_staging/tests/test_clipboard.py index 00c4466b7d48..24925ac42edb 100644 --- a/openedx/core/djangoapps/content_staging/tests/test_clipboard.py +++ b/openedx/core/djangoapps/content_staging/tests/test_clipboard.py @@ -1,7 +1,6 @@ """ Tests for the clipboard functionality """ -from textwrap import dedent from xml.etree import ElementTree from rest_framework.test import APIClient @@ -155,11 +154,11 @@ def test_copy_html(self): assert olx_response.get("Content-Type") == "application/vnd.openedx.xblock.v1.html+xml" # For HTML, we really want to be sure that the OLX is serialized in this exact format (using CDATA), so we check # the actual string directly rather than using assertXmlEqual(): - assert olx_response.content.decode() == dedent(""" - Sample - ]]> - """).lstrip() + assert olx_response.content.decode() == ( + "Sample" + "]]>\n" + ) # Now if we GET the clipboard again, the GET response should exactly equal the last POST response: assert client.get(CLIPBOARD_ENDPOINT).json() == response_data diff --git a/openedx/core/lib/xblock_serializer/block_serializer.py b/openedx/core/lib/xblock_serializer/block_serializer.py index 966380f25061..f12bf5336af5 100644 --- a/openedx/core/lib/xblock_serializer/block_serializer.py +++ b/openedx/core/lib/xblock_serializer/block_serializer.py @@ -133,7 +133,7 @@ def _serialize_html_block(self, block) -> etree.Element: # Escape any CDATA special chars escaped_block_data = block.data.replace("]]>", "]]>") - olx_node.text = etree.CDATA("\n" + escaped_block_data + "\n") + olx_node.text = etree.CDATA(escaped_block_data) return olx_node diff --git a/openedx/core/lib/xblock_serializer/test_api.py b/openedx/core/lib/xblock_serializer/test_api.py index 8078595b0ea9..fe13326ec154 100644 --- a/openedx/core/lib/xblock_serializer/test_api.py +++ b/openedx/core/lib/xblock_serializer/test_api.py @@ -183,6 +183,22 @@ def test_html_with_fields(self): """ ) + def test_html_whitespace_exact(self): + """ + Test that the whitespace with an HTML block's content is preserved. + """ + course = CourseFactory.create(display_name='test course', run="Testing_course") + html_block = BlockFactory.create( + parent_location=course.location, + display_name=" Hello ", + category="html", + data=" 🍔 \n", + ) + serialized = api.serialize_xblock_to_olx(html_block) + assert serialized.olx_str == ( + " 🍔 \n]]>\n" + ) + def test_export_sequential(self): """ Export a sequential from the toy course, including all of its children.