diff --git a/CTFd/admin/pages.py b/CTFd/admin/pages.py index 9dc3d4d3..748bc29d 100644 --- a/CTFd/admin/pages.py +++ b/CTFd/admin/pages.py @@ -25,7 +25,10 @@ def pages_new(): def pages_preview(): # We only care about content. # Loading other attributes improperly will cause Marshmallow to incorrectly return a dict - data = {"content": request.form.get("content")} + data = { + "content": request.form.get("content"), + "format": request.form.get("format"), + } schema = PageSchema() page = schema.load(data) return render_template("page.html", content=page.data.html) diff --git a/tests/admin/test_pages.py b/tests/admin/test_pages.py index d7e3a8cf..33100b37 100644 --- a/tests/admin/test_pages.py +++ b/tests/admin/test_pages.py @@ -13,9 +13,9 @@ def test_previewing_pages_works(): "route": "route", "content": "content_testing", "nonce": sess.get("nonce"), - "draft": "y", - "hidden": "y", - "auth_required": "y", + "draft": True, + "hidden": True, + "auth_required": True, } r = client.post("/admin/pages/preview", data=data) @@ -24,3 +24,46 @@ def test_previewing_pages_works(): assert "content_testing" in resp destroy_ctfd(app) + + +def test_previewing_page_with_format_works(): + """Test that pages can be previewed properly""" + app = create_ctfd() + with app.app_context(): + client = login_as_user(app, name="admin", password="password") + + with client.session_transaction() as sess: + data = { + "title": "title", + "route": "route", + "content": "# content_testing", + "format": "markdown", + "nonce": sess.get("nonce"), + "draft": "y", + "hidden": "y", + "auth_required": "y", + } + + r = client.post("/admin/pages/preview", data=data) + assert r.status_code == 200 + resp = r.get_data(as_text=True) + assert "

content_testing

" in resp + + with client.session_transaction() as sess: + data = { + "title": "title", + "route": "route", + "content": "content_testing", + "format": "html", + "nonce": sess.get("nonce"), + "draft": "y", + "hidden": "y", + "auth_required": "y", + } + + r = client.post("/admin/pages/preview", data=data) + assert r.status_code == 200 + resp = r.get_data(as_text=True) + assert "content_testing" in resp + + destroy_ctfd(app)