1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Stop nested quotes from crashing the website (#70)

This commit is contained in:
Steffo 2019-07-21 23:02:20 +02:00
parent 7d8087b228
commit 96d2dc0a0d

View file

@ -15,7 +15,13 @@ rp = Royalprint("wikiview", __name__, url_prefix="/wiki/view", template_folder=t
required_tables={Royal, WikiPage, WikiRevision}) required_tables={Royal, WikiPage, WikiRevision})
class WikiRenderError(Exception):
"""An error occurred while trying to render the wiki page."""
def prepare_page_markdown(page): def prepare_page_markdown(page):
if list(page.content).count(">") > 99:
raise WikiRenderError("Too many nested quotes")
converted_md = markdown2.markdown(page.content.replace("<", "&lt;"), converted_md = markdown2.markdown(page.content.replace("<", "&lt;"),
extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"]) extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"])
converted_md = re.sub(r"{https?://(?:www\.)?(?:youtube\.com/watch\?.*?&?v=|youtu.be/)([0-9A-Za-z-]+).*?}", converted_md = re.sub(r"{https?://(?:www\.)?(?:youtube\.com/watch\?.*?&?v=|youtu.be/)([0-9A-Za-z-]+).*?}",
@ -37,18 +43,21 @@ def prepare_page_markdown(page):
def prepare_page(page): def prepare_page(page):
if page.format == "markdown": try:
return f.render_template("wikiview_page.html", if page.format == "markdown":
page=page, return f.render_template("wikiview_page.html",
parsed_content=f.Markup(prepare_page_markdown(page)), page=page,
css=page.css) parsed_content=f.Markup(prepare_page_markdown(page)),
elif page.format == "html": css=page.css)
return f.render_template("wikiview_page.html", elif page.format == "html":
page=page, return f.render_template("wikiview_page.html",
parsed_content=f.Markup(page.content), page=page,
css=page.css) parsed_content=f.Markup(page.content),
else: css=page.css)
return error(500, f"Non esiste nessun handler in grado di preparare pagine con il formato {page.format}.") else:
return error(500, f"Non esiste nessun handler in grado di preparare pagine con il formato {page.format}.")
except WikiRenderError as e:
return error(500, f"La pagina Wiki non può essere preparata a causa di un errore: {str(e)}")
@rp.route("/") @rp.route("/")