Skip to content

Commit 0cc0c45

Browse files
geotreringabout
andauthored
return raw post rst when rendering fails (#338)
* return raw post rst when rendering fails * protect against formatting issues --------- Co-authored-by: ringabout <[email protected]>
1 parent 719c5c6 commit 0cc0c45

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/forum.nim

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import frontend/[
2626
category, postlist, error, header, post, profile, user, karaxutils, search
2727
]
2828

29-
from htmlgen import tr, th, td, span, input
29+
from htmlgen import tr, th, td, span, input, `div`, pre
30+
from xmltree import escape
3031

3132
when not declared(roSandboxDisabled):
3233
{.error: "Your Nim version is vulnerable to a CVE. Upgrade it.".}
@@ -314,7 +315,10 @@ proc selectPost(postRow: seq[string], skippedPosts: seq[int],
314315
try:
315316
postRow[1].rstToHtml()
316317
except EParseError:
317-
span(class="text-error", "Couldn't render post #$1." % postRow[0])
318+
`div`(
319+
span(class="text-error", "Couldn't render post #$1, raw RST below." % postRow[0]),
320+
pre(xmltree.escape(postRow[1]))
321+
)
318322

319323
return Post(
320324
id: postRow[0].parseInt,
@@ -369,7 +373,10 @@ proc selectHistory(postId: int): seq[PostInfo] =
369373
try:
370374
row[1].rstToHtml()
371375
except EParseError:
372-
span(class="text-error", "Couldn't render historic post in #$1." % $postId)
376+
`div`(
377+
span(class="text-error", "Couldn't render historic post #$1, raw RST below." % $postId),
378+
pre(xmltree.escape(row[1]))
379+
)
373380
))
374381

375382
proc selectLikes(postId: int): seq[User] =

0 commit comments

Comments
 (0)