mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-19 06:54:20 +01:00
Fix page preview so that it accounts for the provided format (#2091)
* Fix page preview so that it accounts for the provided format * Closes #2089
This commit is contained in:
@@ -25,7 +25,10 @@ def pages_new():
|
|||||||
def pages_preview():
|
def pages_preview():
|
||||||
# We only care about content.
|
# We only care about content.
|
||||||
# Loading other attributes improperly will cause Marshmallow to incorrectly return a dict
|
# 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()
|
schema = PageSchema()
|
||||||
page = schema.load(data)
|
page = schema.load(data)
|
||||||
return render_template("page.html", content=page.data.html)
|
return render_template("page.html", content=page.data.html)
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ def test_previewing_pages_works():
|
|||||||
"route": "route",
|
"route": "route",
|
||||||
"content": "content_testing",
|
"content": "content_testing",
|
||||||
"nonce": sess.get("nonce"),
|
"nonce": sess.get("nonce"),
|
||||||
"draft": "y",
|
"draft": True,
|
||||||
"hidden": "y",
|
"hidden": True,
|
||||||
"auth_required": "y",
|
"auth_required": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
r = client.post("/admin/pages/preview", data=data)
|
r = client.post("/admin/pages/preview", data=data)
|
||||||
@@ -24,3 +24,46 @@ def test_previewing_pages_works():
|
|||||||
assert "content_testing" in resp
|
assert "content_testing" in resp
|
||||||
|
|
||||||
destroy_ctfd(app)
|
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 "<h1>content_testing</h1>" in resp
|
||||||
|
|
||||||
|
with client.session_transaction() as sess:
|
||||||
|
data = {
|
||||||
|
"title": "title",
|
||||||
|
"route": "route",
|
||||||
|
"content": "<test>content_testing</test>",
|
||||||
|
"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 "<test>content_testing</test>" in resp
|
||||||
|
|
||||||
|
destroy_ctfd(app)
|
||||||
|
|||||||
Reference in New Issue
Block a user